将json参数发送到Web服务

时间:2013-07-23 11:02:19

标签: php ajax json web-services

我的任务是废弃网站上的数据。这是网站http://www.centris.ca/en/for-sale 我需要做的是废弃所有属性细节。下面你会看到滑块形式的分页。通过更改页面值,它可以调用webservice并且也可以查看参数。

这是请求的地方 [http://www.centris.ca/Services/PropertyService.asmx/GetPropertyViews]

这些是POST值

{ “的PageIndex”:1, “跟踪”:真}

我尝试使用ajax和curl向此web服务发送请求,但没有运气。 使用ajax,一切都很好,它给了我跨域问题的错误。由于web服务在另一个域上,而我正在从另一个域请求。

 $.ajax({
         type: 'POST',
         contentType: 'application/json; charset=UTF-8',
         url: "http://www.centris.ca/Services/PropertyService.asmx/GetPropertyViews",
         data: '{"pageIndex":2,"track":true}',
         dataType: 'jsonp',
         async: true,
         success: function(msg){
        alert(msg);
    },
         error: function (msg) {
        alert(msg.statusText);
    }
     })

$.ajax({ type: 'POST', contentType: 'application/json; charset=UTF-8', url: "http://www.centris.ca/Services/PropertyService.asmx/GetPropertyViews", data: '{"pageIndex":2,"track":true}', dataType: 'jsonp', async: true, success: function(msg){ alert(msg); }, error: function (msg) { alert(msg.statusText); } })

我也尝试过使用CURL

 $data = array("pageIndex" => 10, "track" => true);                                                                    
 $data_string = json_encode($data);                                                                                   

$ch = curl_init('http://www.centris.ca/Services/PropertyService.asmx/GetPropertyViews?callback=?');                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' . strlen($data_string)));                                                                                                                  
$result = curl_exec($ch);

但它没有帮助。它给我输出“对象移动到这里”,导致它重定向到错误页面。

任何帮助将不胜感激。如果我的问题不明确,请告诉我。

由于

0 个答案:

没有答案
相关问题