腾讯微博开放平台发送微博出现错误"error content len"
我调用腾讯微博开放平台发送微博时出现如下错误:
{"data":null,"detailerrinfo":{"accesstoken":"","apiname":"weibo.t.add","appkey":"801426993","clientip":"119.147.23.18","cmd":
0,"proctime":0,"ret1":2,"ret2":1,"ret3":2,"ret4":2694285578,"timestamp":1384139464},"errcode":2,"msg":"error content len","ret":1,"seqid":594483373099
3456406}
调用方法如下:
URL url = new URL("https://open.t.qq.com/api/t/add?format=json&content=hello&oauth_consumer_key="+AppConfig.QQ_API_KEY+"&access_token="+accessToken+"&openid="+uid+"&clientip="+ip+"&oauth_version=2.a&scope=all");
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
http.setDoOutput(true);
http.setDoInput(true);
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
http.connect();
OutputStream os = http.getOutputStream();
os.flush();
os.close();
InputStream is = http.getInputStream();
int size = is.available();
byte[] jsonBytes = new byte[size];
is.read(jsonBytes);
String message = new String(jsonBytes, "UTF-8");
return message;
请问该如何解决?谢谢!!!
------解决方案--------------------
http.setRequestProperty("Content-Type","multipart/form-data; boundary="+ contentType.Substring(contentType.IndexOf('"')+1,contentType.LastIndexOf('"')-contentType.IndexOf('"')-1));