gpt4 book ai didi

c# - 获取 Curl 生成的 POST 流的示例以协助移植到 C#

转载 作者:可可西里 更新时间:2023-10-31 23:38:59 25 4
gpt4 key购买 nike

我的任务是转换以下 PHP 代码块以执行 HTTP 多部分发布。我了解做 HTTP 帖子的基础知识(我的代码已经做了一些 JSON 的帖子)并且我已经阅读了多部分请求的基础知识。但是,Curl 显然在幕后做了很多 腿部工作,这些工作必须转换为 .NET 流写入。然而,对于这些事情,细节决定成败。

不熟悉 Curl 并且是 PHP 新手,有没有办法使用代码查看最终使用 curl_exec 发送的请求?有一个现实生活中的例子真的很有帮助。事实上,我对简单的字段没意见——每个字段都有一个单独的边界/部分。 JPEG 图像编码对我来说是一个棘手的问题。我可以设置一个 PHP 环境并以某种方式调试它吗?我推断 Curl 是一种网络客户端,即它可以在没有用户界面的情况下完成网络浏览器的大部分工作。

<?php

function AddPhoto( $account, $password, $pubId, $photoId, $owner, $pubDate, $attribution, $caption, $keywords, $photoPath )
{
// set up the arguments of the multipart form data
$args = array( 'Method' => 'AddPhoto', 'Account' => 'Test', 'Password' => 'pw',

'PubID' => 'WOR/1002',
'PhotoID' => '12345',
'Owner' => 'me',
'PubDate' => '2015-07-01',
'Attribution' => '',
'Caption' => 'the front door',
'Keywords' => 'Pub',

'Photo' => new CurlFile( $photoPath, // path to the file
'image/jpeg', // MIME type of the file
'image' // file name (not used)
)
);

// create a curl request object
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://dev.camrapubs.org.uk/simon/PubDatabase/API2.php');
curl_setopt( $ch, CURLOPT_POST, 1 ); // use the POST method
curl_setopt( $ch, CURLOPT_POSTFIELDS, $args ); // supply the arguments for the POST
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // ensure curl_exec returns the result rather than echoing it

// make the call and get the result
return curl_exec($ch);
}

$result = AddPhoto( ‘xx', ‘xx', 'WOR/1002', '12345', 'me', '2015-07-01', 'copyleft', 'The front door', 'Pub', 'sample.jpg' );
echo 'result = ', $result, PHP_EOL;
?>

最佳答案

罗布,

也许你应该看看这个?

Php - Debugging Curl

祝你成功:-)

关于c# - 获取 Curl 生成的 POST 流的示例以协助移植到 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32489682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com