如何使用php调用其他网址?

时间:2017-05-19 09:22:41

标签: php web-services curl

当我使用邮差应用程序点击以下网址时工作正常

http://192.168.1.220/cgi-bin/handle_login.tcl

但是当尝试使用curl时,它会给我以下错误

           counter += 1
            roads = ""
            for m in suggestedroute:
                if suggestedroute is not 0:
                    output = "If you're taking Route " + counter.__str__() + " try to avoid: "
                    roads += m
                    if counter is not 1:
                        result += ". "+output + roads
                    else:
                        result +=output + roads

            self.app.html = u"<div style='color:red'> "+result+u"<div>"

以下是我的PHP代码

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

1 个答案:

答案 0 :(得分:0)

我已经纠正了我的代码中的错误,我得到了理想的答案......

以下是答案

    $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,"URL");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS,
    "key1=value1&key2=value2&key3=value3");         
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Send the request 
     $response = curl_exec($ch);
     curl_close ($ch);
     echo "$response";