search

Home  >  Q&A  >  body text

php - file_get_contents implements POST data, https

As the title states, regardless of the curl method, POST is given to the interface data, but the interface cannot obtain it or there is a problem with returning parameters.

Post the code:

    $POSTFIELDS = array("receipt-data" => $receipt_data);    //
    $POSTFIELDS = json_encode($POSTFIELDS);    // 注释了也没用
    $url = "https://sandbox.itunes.apple.com/verifyReceipt";

    $context = stream_context_create(array(
        'http' => array(
            'method'  => 'POST',
            'header'  => "Content-type: application/x-www-form-urlencoded",
            'content' => http_build_query($POSTFIELDS),
            'timeout' => 20,
        )
    ));
    return file_get_contents($url, false, $context);

$receipt_data data format is correct because curl testing can return correct information.

But for file, the returned parameters are always wrong no matter what. I don’t know what the problem is.

给我你的怀抱给我你的怀抱2780 days ago711

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-27 17:44:27

    What you said upstairs is correct. Regarding this problem, it is actually an error when interacting with the Apple payment interface and transmitting data.

    http_build_query is not required

    reply
    0
  • 某草草

    某草草2017-05-27 17:44:27

    Let’s first see what the server gets. . . Are you passing json? Then there is the POST in form format. . . Without key=>value, the backend can only get strings in json format

    reply
    0
  • ringa_lee

    ringa_lee2017-05-27 17:44:27

    HTTPS needs to enable SSL
    Get this to help you
    http://www.jb51.net/article/4...

    reply
    0
  • Cancelreply