相当于PHP中Java的PostMethod


Equivalent of PostMethod of Java in PHP

我想问一下是否存在一个PHP函数来模拟Codeigniter中的这段代码。

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 的响应。

谢谢。

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

$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);