php
  • http-post
  • 2015-09-29 54 views 0 likes 
    0

    我想發送一個帖子請求到一個url,但它說這不是一個post請求。請幫助,這是我的代碼。發佈方法到遠程URL不工作在php

    <?php 
    
    $url = "myurl"; 
    $api = '{"Project-Key" : "string","MailFrom" : "email","From" : "email","To" : "email","Subject" : "Mail Subject","HtmlBody" : "<html><body> <img src="cid:naz.jpg"> </body> </html>"}'; 
    
    $data = array(
         "authtoken" => "token", 
         "scope" => "mail", 
         "mailDetails" => $api 
    ); 
    
    $options = array(
        'http' => array(
         'header' => "Content-type: application/x-www-form-urlencoded\r\n", 
         'method' => 'POST', 
         'content' => http_build_query($data) 
        ) 
    ); 
    
    $context = stream_context_create($options); 
    $result = file_get_contents($url,false, $context); 
    $result = json_decode($result, true); 
    
    print_r($result); 
    exit(0); 
    
    ?> 
    
    +0

    看看PHP的捲曲功能,你應該使用它們發送POST請求。 http://php.net/manual/en/book.curl.php – AJReading

    回答

    0

    剛剛嘗試使用捲曲:

    $curlConfig = [ 
        CURLOPT_URL   => $url, 
        CURLOPT_RETURNTRANSFER => true, 
        CURLOPT_POST   => true, 
        CURLOPT_POSTFIELDS  => $data 
    ]; 
    
    curl_setopt_array($ch, $curlConfig); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    
    +0

    這也不適合我。 – Raju

    相關問題