【问题标题】:Equivalent of PostMethod of Java in PHPPHP中Java的PostMethod等价物
【发布时间】:2015-03-17 03:00:31
【问题描述】:

请问Codeigniter中是否有PHP函数可以模拟这段代码。

HttpClient httpClient       = new HttpClient();
PostMethod postMethod       = new PostMethod(requestURL);
NameValuePair[] datas       = {new NameValuePair("studentnumber", studentnumber), 
                              new NameValuePair("studentdata", encryptedData)};

postMethod.setRequestBody(datas);
int statusCode      = httpClient.executeMethod(postMethod);
byte[] responseByte = postMethod.getResponseBody();
String responseBody = new String(responseByte, "UTF-8");

curl 似乎不起作用,而 $this->output->set_output 正确传递数据但未能捕获 requestUrl 的响应。

谢谢。

【问题讨论】:

    标签: java php codeigniter http-post


    【解决方案1】:

    我能够使用我在HTTP POST from PHP, without cURL 上找到的这段代码捕获来自 requestUrl 的响应(非常感谢)。

    $options = array(
        'http' => array(
            'method' => "POST",
            'header' => "Accept-language: en\r\n" . "Content-type: application/x-www-form-urlencoded\r\n",
            'content' => http_build_query(array(
                'studentnumber' => $studentnumber,
                'studentdata' => $encryptedData,
            ),'','&'
        )
    ));
    
    $refno = file_get_contents($requestUrl,false,$context);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2019-11-03
      • 2012-09-14
      • 2010-09-23
      • 2017-06-13
      • 1970-01-01
      相关资源
      最近更新 更多