du548397507 2019-01-16 06:02
浏览 65

错误的签名尝试将curl中的文件上载转换为C#

I'm trying to upload a file with Keep2Share api

In the documentation are a Php Implementation, which are the following

$data = $this->getUploadFormData($parent_id, $preferred_node);
$curl = curl_init();
        $postFields = $data['form_data'];

        $postFields[$data['file_field']] = new CURLFile($file);

        curl_setopt_array($curl, [
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_URL => $data['form_action'],
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $postFields,
        ]);

        $response = curl_exec($curl);
        if ($this->verbose) {
            echo '<<', $response, PHP_EOL;
        }
        return json_decode($response, true);

getUploadFormData method return a json with the following data

status: [success]
status_code: [200,400]
form_action: string
file_field: string
form_data: [
    params: string
    signature: string
]

But i need to translate it to C#, i'm trying the following

//dat is a object with getUploadForm data
var dat = await this.GetUploadFormData();

        HttpContent stringContent = new StringContent(dat.form_data.signature);
        HttpContent bytesContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filename));

        using (var client = new HttpClient())

        using (var formData = new MultipartFormDataContent())
        {
            formData.Add(stringContent, "signature", "signature");
            formData.Add(bytesContent, "file", "file");
            var response = await client.PostAsync(dat.form_action, formData);

            using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync()))
            {
                Console.WriteLine(await reader.ReadToEndAsync());
            }

            return await response.Content.ReadAsStreamAsync();
        }

But i'm getting

{"name":"Bad Request","message":"Wrong signature. IP 1**.58.*54.213","code":0,"status":400}

I'm almost sure that my problem is that I'm not passing the signature parameter as it should be

is that the case?

what i'm doing wrong?

Thanks!

EDIT

An example of getUploadFormData object should be

   "status":"success",
   "code":200,
   "form_action":"http://file-api-27.keep2share.cc:8000/upload",
   "file_field":"file",
   "form_data":{  
      "ajax":true,
      "_params":null,
      "signature":"2eda59a25137a78ef05513c60182cebe9972d9d1b80d9e643e0a8104dcdf42f59cfbc76680c7caf2d93e090c74ebdcf19da664c53e9da14992d604469a634887"
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效