我用fiddler和C#写的一个请求XML
var client = new HttpClient(); var content = new StringContent(strXML, Encoding.GetEncoding("GBK")); //content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); var result = client.PostAsync(apiUrl, content).Result; return result.Content.ReadAsStringAsync().Result;
都报异常,返回的异常信息
<?xml version="1.0" encoding="gb2312"?><PACKET><HEAD><SystemCode></SystemCode><ResponseType>0</ResponseType><ErrorMessage><![CDATA[The element type "CarOwner" must be terminated by the matching end-tag "</CarOwner>".]]></ErrorMessage></HEAD></PACKET>
接口供应商给我说的意思是我这里对流长度做限制了
改用java写是正常的
public static String net(String strUrl, String method) throws Exception { HttpURLConnection conn = null; BufferedReader reader = null; String rs = null; try { URL url = new URL(strUrl); URLConnection con = url.openConnection(); con.setDoOutput(true); con.setRequestProperty("Pragma:", "no-cache"); con.setRequestProperty("Cache-Control", "no-cache"); con.setRequestProperty("Content-Type", "text/xml"); OutputStreamWriter out = new OutputStreamWriter(con .getOutputStream()); String xmlInfo=readFileContent(FILEXML); System.out.println("urlStr=" + strUrl); System.out.println("xmlInfo=" +xmlInfo); out.write(xmlInfo); out.flush(); out.close(); BufferedReader br = new BufferedReader(new InputStreamReader(con .getInputStream())); String line = ""; for (line = br.readLine(); line != null; line = br.readLine()) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { reader.close(); } if (conn != null) { conn.disconnect(); } } return rs; }
大神谁知道是怎么回事,困扰一星期了
拉丁的传说
慕容3067478
慕工程0101907
相关分类