用eclipse java写了一个post方法可以post成功,但是用android 用同样的方法上传失败,搞了两三天了,急求啊!!!!!!post 方法public static void appadd(String weburl,String json) {
try {
//鍒涘缓杩炴帴
URL url = new URL(weburl);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type",
"application/json");
connection.connect();
//POST璇锋眰
DataOutputStream out = new DataOutputStream(
connection.getOutputStream());
out.writeBytes(json);
out.flush();
out.close();
//璇诲彇鍝嶅簲
BufferedReader reader = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String lines;
StringBuffer sb = new StringBuffer("");
while ((lines = reader.readLine()) != null) {
lines = new String(lines.getBytes(), "utf-8");
sb.append(lines);
}
System.out.println("result---------->"+sb.toString());
reader.close();
connection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
客户端返回的错误提示:result---------->与“string.this[int]”最匹配的重载方法具有一些无效参数
.net服务端接受数据解析的代码
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ss.yn15.com:8800/Interface/EditRFID");//第一个接口地址
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://ss.yn15.com:8800/api/InterfaceRFID/Edit");//第二个接口地址
request.Method = "POST";
//request.ContentType = "application/x-www-form-urlencoded";//第一个接口使用
request.ContentType = "application/json";// application/json 第一个、第二个接口都可使用使用
byte[] buffer = Encoding.UTF8.GetBytes("{\"list\": {\"updated\": [{\"ApprovePerson\": \"\",\"ApproveState\": \"\",\"FZStatus\": \"178\", \"LeaveType\": \"209\",\"ProjectCode\": \"201306030001\",\"RFIDPerson\": \"\", \"RFID_id\": \"S0019\",\"SheepStatus\": \"134\",\"bas_pen_id\": \"000040\",\"birthday\": \"2015-09-29\",\"breed\": \"285\",\"breed_count\": \"2\",\"chip\": \"982123472852295\",\"createtime\": \"2015-08-26\",\"female_RFID\": \"\",\"grade\": \"\",\"introduce_source\": \"118\",\"introduce_time\": \"2015-9-27\",\"introduce_weight\": 3.76,\"isdead\": \"\",\"isenable\": true,\"isout\": \"\",\"isweekout\": \"\",\"male_RFID\": \"E47353\",\"mother_breednum\": \"0\",\"note\": \"\",\"purpose\": \"122\",\"changeStatus\": \"modify\",\"rfidStatus\": \"\",\"sex\": \"3334\",\"weaningdate\": \"2015-08-27\",\"weaningday\": 0,\"weaningweight\": 1.0 }],\"inserted\": [],\"deleted\": [],\"_changed\": true}}");
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string result = reader.ReadToEnd();
string asb;
// XmlDocument xx = new XmlDocument();
// xx.LoadXml(result);
//return xx;
}
}
catch (Exception ex)
{
ex = new Exception("postXMLByResponseError:" + ex.Message);
throw ex;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。