我试图从桌面应用程序连接到一个URL,我得到我的问题的标题中指示的错误,但当我尝试从servlet连接到相同的URL时,一切正常.当我从浏览器加载URL时,一切正常.我在servlet中使用相同的代码.代码在库中,当它不起作用时,我将代码拉出到当前项目中的一个类,但它没有用.
网址https://graph.facebook.com/me.
代码片段.
public static String post(String urlSpec, String data) throws Exception {
URL url = new URL(urlSpec);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(data);
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = "";
StringBuilder builder = new StringBuilder();
while((line = reader.readLine()) != null) {
builder.append(line);
}
return builder.toString();
}
Run Code Online (Sandbox Code Playgroud)
我在这里有点困惑,是否存在一些不是普通桌面应用程序的servlet?
谢谢.
完全堆积的痕迹
Feb 8, 2011 9:54:14 AM com.trinisoftinc.jiraffe.objects.FacebookAlbum create
SEVERE: null
java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/me …Run Code Online (Sandbox Code Playgroud) 我有这个方法
private def getAddresses(data: List[Int], count: Int, len: Int): Tuple2[List[Address], List[Int]] = {
if (count == len) {
(List.empty, List.empty)
} else {
val byteAddress = data.takeWhile(_ != 0)
val newData = data.dropWhile(_ != 0).tail
val newCount = count + 1
val newPosition = byteAddress.length + 1
val destFlag = byteAddress.head
if (destFlag == SMEAddressFlag) {
(SMEAddress().fromBytes(byteAddress) :: getAddresses(newData, newCount, len)._1, newPosition :: getAddresses(newData, newCount, len)._2)
} else {
(DistributionList().fromBytes(byteAddress) :: getAddresses(newData, newCount, len)._1, newPosition :: getAddresses(newData, newCount, len)._2)
} …Run Code Online (Sandbox Code Playgroud)