如何在PHP中以ITMS url发送get请求?

时间:2012-04-26 15:34:44

标签: php ios plist

我有以下代码无效。意味着ITMS服务不会使用get请求调用URL。

header('Location: itms-services://?action=download-manifest&url=http://www.mysite.com/plistReader.php?id=123');

如果我删除id=123它的开始工作。但我需要发送它以保持id动态。在Session中我也无法通过。请帮忙。

2 个答案:

答案 0 :(得分:6)

您需要将该问号进行网址编码为%3F,因为它是一个保留字符。正如@wroniasty指出的那样,您还需要将=编码为%3D

header('Location: itms-services://?action=download-manifest&url=http://www.mysite.com/plistReader.php%3Fid%3D123');

另请参阅:http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

答案 1 :(得分:1)

永远不要手动转义URL字符。让PHP 5的功能 - urlencode()http_build_query()为您付出艰苦的努力。这可以避免一些GET参数名称/值对可能包含需要传输的敏感字符的问题,例如

<?php
    $base_url = "http://www.example.com/plistReader.php";
    $data = Array("id" => 123, "dangerous" => ":?&= are some sensitive chars");

    $itms_url = "itms-services://?action=download-manifest&url=" . urlencode($base_url . "?" . http_build_query($data));
    header('Location: ' . $itms_url);
?>