网页从别的网域获取资料
1.jsonp
$(function(){
//"http://192.168.1.243:8080/practies/demo/testJsonp?callback=?"
//"http://192.168.1.167:8080/member/testJsonp?callback=?"
jQuery.getJSON("http://192.168.1.243:8080/practies/demo/testJsonp?callback=?",
function(result) {
alert(result);
alert("Symbol === " + result.Symbol + "Price ===" + result.Price);
});
})
@ResponseBody
@RequestMapping(value = "/testJsonp")
public String testJsonp(HttpServletRequest request , @RequestParam("callback") String callback){
String jsonData = "{Symbol: 'IBM', Price: 91.42}" ;
String output = callback + "(" + jsonData + ");";
return output ;
}
2.httpclient
/**
* commons-httpclient-3.1.jar、commons-logging-1.0.4.jar、commons-codec-1.3.jar
*/
public static void main(String[] args) {
String sendUrl = "http://static.99114.com/static/js/common/area.js";
HttpClient client = new HttpClient();
HttpMethod getMethod = new GetMethod(sendUrl);
getMethod.setRequestHeader(new Header("Accept-Language", "zh-cn"));
try {
client.executeMethod(getMethod);
if (getMethod.getStatusCode() == 200) {
String jsonStr = getMethod.getResponseBodyAsString();
System.out.println("------------"+jsonStr);
}
} catch (Exception e) {
}
}

浙公网安备 33010602011771号