开发者

How I can get data after make a POST to an external HTTPS Web Page?

I need to make a POST in JSON format to an HTTPS web page in a remote server and receive an answer in JSON format.

The data to be send it to the remote server is take it from the URL (bar)<---Done in PHP

My problem is to send this data and receive an answer.

I tried making it in PHP, and HTML using cURL(php) and submit(html).

The results: In PHP I can't send anything. In HTML I can submit the data, get an answer but I can't catch in my code.

I see the answer using Wireshark, and as I see the POST is make it after a negotiation protocol, and as I said I receive an answer(encoded due to HTTPS, I think).

Now I need receive that answer in my code to generate an URL link so I'm considering to use Java Script.

I never do something similar before.

Any suggestion will be appreciated, thanks.


I'm using the following code with not result but a 20 seconds of delay until a blank page.

<?php
$url = 'https://www.google.com/loc/json';
$body = '{"version":"1.1.0","cell_towers":[{"cell_id":"48","location_area_code":1158,"mobile_country_code":752,"mobile_network_code.":7,"age":0,"signal_strength":-71,"timing_advance":2255}]}';
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $body);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($c, CURLOPT_HTTPHEADERS,'Content-Type: application/json');
$page = curl_exec($c);
echo($page);
//print_r($page);
curl_close($c);
?>

New info

I Just get new very important info

"The Gears Terms of Service prohibits direct use of the Google location server (http://www.google.c开发者_运维技巧om/loc/json) via HTTP requests. This service may only be accessed through the Geolocation API."

So, I was going trough the wrong way, and from now I will start to learn about Gears in order to apply the Gears API.

Cheers!


There's no real reason PHP couldn't do the PHP for you, if you set things up properly.

For instance, it may require a cookie that it had set on the client browser at some point, which your PHP/curl request doesn't have.

To do proper debugging, use HTTPFox or Firebug in Firefox, which monitor the requests from within the browser itself, and can show the actual data, not the encrypted garbage that wireshark would capture.

Of course, you could use the client browser as a sort of proxy for your server. Browser posts to the HTTPS server, gets a response, then sends that response to your server. But if that data is "important" and shouldn't be exposed, then the client-side solution is a bad one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜