c# - What kind of the Content-Type will this request use? -


i trying access data service through http request using c# httpwebrequest. when contenttype x-www-form-urlencoded, works. need transfer files in request, used multipart/form-data , ran 401 error service. looks need somehow put files in x-www-form-urlencoded, how?

i have working code in php. can explain, contentype uses in generated request and, thereafter, how files encoded?

<?php function encode($str) {   return iconv("windows-1251", "utf-8", $str); } function decode(&$resp) {   if (is_array($resp)) {     foreach ($resp $key => $value) {       if (is_string($value))         $resp[$key] = iconv('utf-8','windows-1251', $value);       else          decode($value);     }   } }  $url = "https://demo.krate.ru/api/v1/reports.json"; $api_key = "zzvahvcj6rg1dazaxo_c";  $request = array(     'request[acceptance]' => '@d:/users/rangerx/downloads/yvfurusnvwk.jpg',     'request[passport_scan]' => '@d:/users/rangerx/downloads/yvfurusnvwk.jpg',     'request[reg_idx]' => '445000' );  $curl = curl_init($url); curl_setopt($curl, curlopt_header, false); curl_setopt($curl, curlopt_returntransfer, true); curl_setopt($curl, curlopt_ssl_verifypeer, true);  curl_setopt($curl, curlopt_ssl_verifyhost, 2); curl_setopt($curl, curlopt_cainfo, "d:\\dev\\projects\\krate2_demo\\doc\\v1-api-client-example\\addtrustexternalcaroot.crt");  curl_setopt($curl, curlopt_post, true); curl_setopt($curl, curlopt_postfields, $request);  $json_response = curl_exec($curl);  $status = curl_getinfo($curl, curlinfo_http_code); if ( $status != 200 && $status != 201 ) {   die("error: call url $url failed status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl)); } curl_close($curl);  $response = json_decode($json_response, true); // chcp 65001 var_dump($response); ?> 

you can't transfer files within x-www-form-urlencoded - investigate why getting response authenticate instead.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -