D
D
Doston Elmurodov2018-04-19 08:59:22
ASP.NET
Doston Elmurodov, 2018-04-19 08:59:22

How to send XML data by POST method with login and password, login password is not in XML body in C# language?

How to send XML data using the POST method with login and password, login password is not in the XML body in C#
This code is in PHP, it needs to be written in C#.

<?php
$xmlData = 'XML data';
$username = "test";
$password = "test";

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, "https://example.com");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "XML=".$xmlData);
$response=curl_exec($ch);
if($response === FALSE){
    die(curl_error($ch));
}
 else {echo $response;}
?>

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-04-19
@vshvydky

there is a corresponding header for passwords in the protocol, called authorization
there is basic authorization, this is where the login and password seem to be separated by a colon (I don’t remember exactly, but it’s easy to google) and wrapped in base64, you just read the documentation on this topic. Why make a fuss about yourself when there is a RFC?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question