简体   繁体   English

Http请求和响应

[英]Http Request&Response

I have to make a request to a pipl.com ( http://apis.pipl.com//search/v2/json/?email=maryuca_alias%40yahoo.com&person_mode=all&exact_name=0&no_sponsored=0&key=myKey ) in oder to get some information about a person.The response of this request is a json object. 我必须在oder上向pipl.com( http://apis.pipl.com//search/v2/json/?email=maryuca_alias%40yahoo.com&person_mode=all&exact_name=0&no_sponsored=0&key=myKey )进行请求才能获取有关人的一些信息。此请求的响应是一个json对象。 I am not able to do this with a ajax/jquery/jsonp call because their server does not support this types of call. 我无法通过ajax / jquery / jsonp调用来做到这一点,因为他们的服务器不支持这种类型的调用。 Is there a way to process the response on server side (I use Struts 1) or client side? 有没有办法在服务器端(我使用Struts 1)或客户端上处理响应?

If you have a solution ,please answer this question. 如果您有解决方案,请回答此问题。

<html>
<head>
</head>
<body>
<script type="text/javascript">
function getJSONP(url, success) {
var ud = '_' + +new Date,
script = document.createElement('script'),
head = document.getElementsByTagName('head')[0] 
|| document.documentElement;
window[ud] = function(data) {
head.removeChild(script);
alert(data);
success && success(data);
};
script.src = url.replace('callback=?', 'callback=' + ud);
head.appendChild(script);
}
getJSONP('http://apis.pipl.com//search/v2/json/?email=maryuca_alias
%40yahoo.com&person_mode=all&exact_name=0&no_sponsored=0
&key=key&callback=?', function(data){
console.log(data);
});     
</script>
</body>
</html>

Use something like HttpClient to make the request from Java, probably in a service called by the action class. 使用HttpClient之类的内容来从Java发出请求,可能是在操作类调用的服务中。 That response can be processed by either Java or JavaScript, depending on your needs. 该响应可以通过Java或JavaScript处理,具体取决于您的需求。

ok, it looks like u make a valid cross site request, but u get header different than expected or data not JSON formated? 好的,看起来您发出了有效的跨站点请求,但是您获得的标头与预期的不同或数据不是JSON格式的吗?

if its just headers of response are not proper u can always parse data on client side. 如果仅响应头不正确,则始终可以在客户端解析数据。 best way to specify problems would be pasting headers of request, response and code 指定问题的最佳方法是粘贴请求,响应和代码的标头

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM