package testinterface;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;
public class dda {
public static void main(String[] args) {
try {
HttpClient httpclient = new DefaultHttpClient();
String uri = "http://193.168.1.102:8080/project/answerOfQuestion/list.xml";
System.out.println("bbbbbbbb");
HttpPost httppost = new HttpPost(uri);
//添加http头信息
httppost.addHeader("Authorization", "your token"); //认证token
httppost.addHeader("Content-Type", "application/json");
httppost.addHeader("User-Agent", "imgfornote");
//http post的json数据格式: {"name": "your name","parentId": "id_of_parent"}
System.out.println("test111111");
JSONObject obj = new JSONObject();
obj.put("name", "your name");
obj.put("parentId", "your parentid");
httppost.setEntity(new StringEntity(obj.toString()));
System.out.println("bbbbbbbbb");
System.out.println("eeeeeeeeee");
HttpResponse response;
System.out.println("rrrrrrrr");
response = httpclient.execute(httppost);
System.out.println("mmmmmmmmm");
//检验状态码,如果成功接收数据
int code = response.getStatusLine().getStatusCode();
System.out.println(code+"qqqqqqqq");
if (code == 200) {
// String rev = EntityUtils.toString(response.getEntity());//返回json格式: {"id": "27JpL~j4vsL0LX00E00005","version": "abc"}
// System.out.println(rev+"11111111");
// obj = new JSONObject(rev);
//
// String id = obj.getString("id");
// System.out.println(rev+"222222222");
// String version = obj.getString("version");
// System.out.println(rev+"333333333");
System.out.println("wawawawa");
}
} catch (ClientProtocolException e) {
} catch (IOException e) {
} catch (Exception e) {
}
}
try {
BufferedInputStream in = new BufferedInputStream(request.getInputStream());
int i;
char c;
while ((i=in.read())!=-1) {
c=(char)i;
System.out.print(c);
}
System.out.println();
System.out.println("test");
}catch (Exception ex) {
ex.printStackTrace();
}
}
报错信息如下:
If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
这个是什么鬼?
http://193.168.1.102:8080/project/answerOfQuestion/list.xml
难道是你服务器路径?
前辈能否发您的安卓项目源码发我一份,我也说不清自己那块出问题了packagecom.proxy.test;版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。