我有Json文字:
{"searchParams":{"cnt":5,"Bounds":{"NorthEast": "Latitude":"48.5166043488675","Longitude":"-67.5"},"SouthWest":{"Latitude":"25.7207351344121","Longitude":"-126.38671875"}},"HomesAvailableNow":[0],"BrandId":[4]}}
我有url = http://www.mypage.com/AjaxWebServices/MapService.asmx/FilterByQueryString,我想发布请求并接收数据。
请帮帮我......
答案 0 :(得分:2)
使用URLConnection发布数据:
String data = "json";
URL url = new URL(urlString);
URLConnection conn;
conn = url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
}
wr.close();
rd.close();
return rd.toString();