// HTTP POST request private void sendPost() throws Exception { String url = "https://selfsolve.apple.com/wcResults.do"; URL obj = new URL(url); HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345"; // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending "POST" request to URL : " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //print result System.out.println(response.toString()); }
解决方案
10
浏览器接收语言的类型
5
部分服务器要根据user agent判断浏览器类型,你填上一种就可以了
response对象:没有对象,只有报文,response就是返回报文
10
上游接口接受数据是这么接受的
BufferedReader bf=req.getReader();
String temp=null;
StringBuilder sb=new StringBuilder();
while((temp=bf.readLine())!=null){
sb.append(temp);
}
System.out.println(sb.toString());
从流里面读取,也可以直接
@RequestMapping(“queryList”)
@ResponseBody
public void queryList(@RequestBody Map<String ,String> map){
}直接转换成map,这个要配置spring的转换器,里面其实就是上面的
BufferedReader bf=req.getReader();
String temp=null;
StringBuilder sb=new StringBuilder();
while((temp=bf.readLine())!=null){
sb.append(temp);
}
System.out.println(sb.toString());
从流里面读取,也可以直接
@RequestMapping(“queryList”)
@ResponseBody
public void queryList(@RequestBody Map<String ,String> map){
}直接转换成map,这个要配置spring的转换器,里面其实就是上面的