dongshan0202405 2012-09-13 15:40
浏览 55
已采纳

如何使用我的PHP端点的响应以编程方式发送URL变量

I have a basic API endpoint set up on my site, which a 3rd party site will use to verify certain info that is entered into a form by the user.

Here's the flow: 1. User is on 3rd party site. 2. User enters info into a form 3. Info is sent to my site's endpoint. 4. My site checks the information and returns a JSON object.

As you can see from #4, my API is currently set up to return a JSON object. After the info is checked, something like this happens:

    header('content-type: application/json; charset=utf-8');
    echo json_encode($response);
    exit;

However, the 3rd party site is only set up to receive URL variables. Is there a way to pass back url variables programmatically? I realize I could theoretically send a new request, but it's not clear to me where that request should go (the internal workings of the 3rd party site aren't well documented), so I'd much prefer to send it as a response.

I hope this makes sense. Please comment if it doesn't. Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dprc88435 2012-09-13 18:18
    关注

    You don't get to send GET/POST parameters in the response, but in the response body you can send whatever you want in whatever format you want - and they can use curl or file_get_content and parse it on their side (3rd party's website).

    For example (on the 3rd party's website):

    //setting a call to your server
    $opts = array('http' =>
      array(
        'method'  => 'POST',
        'header'  => "Content-Type: text/xml
    ".
          "Authorization: Basic ".base64_encode("$https_user:$https_password")."
    ",
        'content' => $body,
        'timeout' => 60
      )
    );
    
    $context  = stream_context_create($opts);
    $url = 'https://'.$https_server;
    // Here they call your server
    $result = file_get_contents($url, false, $context, -1, 40000);
    // Here you'll parse the $result
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作