如何在对外部HTTPS网页进行POST后获取数据? [英] How I can get data after make a POST to an external HTTPS Web Page?

查看:137
本文介绍了如何在对外部HTTPS网页进行POST后获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以JSON格式将POST发送到远程服务器中的HTTPS网页,并以JSON格式接收答案。

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.

要发送的数据到远程服务器是从URL(bar)< ---在PHP中完成

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.

我尝试用PHP制作它,并使用cURL(php)和提交(html)进行HTML。

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

结果:在PHP中我无法发送任何内容。
在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.

我看到了使用Wireshark的答案,而我看到POST是在协商协议之后制作的,正如我所说的,我收到了一个答案(由于HTTPS编码,我认为)。

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).

现在我需要得到答案在我的代码中生成一个URL链接所以我正在考虑使用Java Script。

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.

我使用以下代码而不是结果但是延迟20秒直到空白页。

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);
?>

新信息

我刚收到新的重要信息

Gears服务条款禁止直接使用Google位置服务器(http://www.google .com / loc / json)通过HTTP请求。这项服务只能通过Geolocation API访问。

所以,我错了方式,从现在开始我将开始学习Gears以应用Gears 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.

干杯!

推荐答案

如果您正确设置,PHP无法为您执行PHP。

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

例如,它可能需要在某个时刻在客户端浏览器上设置的cookie,这是您的PHP / curl请求所没有的。

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.

要进行正确的调试,请使用Firefox中的HTTPFox或Firebug,它监视来自浏览器本身的请求,并且可以显示实际数据,而不是显示的加密垃圾reshark会捕获。

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.

当然,您可以将客户端浏览器用作服务器的一种代理。浏览器发布到HTTPS服务器,获得响应,然后将该响应发送到您的服务器。但是,如果该数据重要且不应公开,那么客户端解决方案就是一个糟糕的解决方案。

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.

这篇关于如何在对外部HTTPS网页进行POST后获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆