PHP cURL函数生成什么请求?
我目前正在编写一个与PHP页面集成的C#windows服务。我有一个用PHP发出请求的代码示例,如下所示,但我从未用PHP开发过,不了解cURL函数如何执行请求 是否仍然可以检索正在发送的请求?或者任何人都可以提供一个示例,说明请求的外观和发送方式,这样我就可以在C#中复制请求 谢谢你的帮助PHP cURL函数生成什么请求?,php,asp.net,curl,Php,Asp.net,Curl,我目前正在编写一个与PHP页面集成的C#windows服务。我有一个用PHP发出请求的代码示例,如下所示,但我从未用PHP开发过,不了解cURL函数如何执行请求 是否仍然可以检索正在发送的请求?或者任何人都可以提供一个示例,说明请求的外观和发送方式,这样我就可以在C#中复制请求 谢谢你的帮助 public function api(/* polymorphic */) { $args = func_get_args(); if (is_array($args[0])) {
public function api(/* polymorphic */) {
$args = func_get_args();
if (is_array($args[0])) {
$serviceId = $this->getApiServiceId($args[0]["method"]);
unset($args[0]["method"]);
$args[0]["serviceId"] = $serviceId;
$args[0]["dealerId"] = $this->dealerId;
$args[0]["username"] = $this->username;
$args[0]["password"] = $this->password;
$args[0]["baseDomain"] = $this->baseDomain;
return json_decode($this->makeRequest($args[0]));
} else {
throw Exception("API call failed. Improper call.");
}
}
protected function makeRequest($params, $ch=null) {
if (!$ch) {
$ch = curl_init();
}
$opts = self::$CURL_OPTS;
if ($this->useFileUploadSupport()) {
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if ($result === false) {
$e = new WPSApiException(array(
'error_code' => curl_errno($ch),
'error' => array(
'message' => curl_error($ch),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}
将选项CURLINFO\u HEADER\u OUT添加到curl handle,然后在执行后调用curl\u getinfo 例如:
//...
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
//...
curl_exec($ch);
//...
$header = curl_getinfo(CURLINFO_HEADER_OUT);
echo $header;
php函数
curl\u getinfo
可能会对您有所帮助。旁注:我认为编写这段PHP代码的人混淆了多态性和变量函数。你能创建一个简单的套接字服务器并将请求发送到那里进行分析吗?