опубликовать веб-запрос с vb.net на php

1

У меня проблема при использовании webrequest для перехода на php

поэтому мне нужно передать параметр в php, как показано ниже.

это в php

public function get_token()
{
$client = new \GuzzleHttp\Client;

$requestdata = [
[
"name"=>'grant_type',
"contents" => 'client_credentials'
],
[
"name"=>'client_id',
"contents" => 'testclient'
],
[
"name"=>'client_secret',
"contents" => 'abcdefghijklmnopqrstuvwxyz12341234567890'
]
];

$response = $client->request('POST','http://abc123.local/authorizations', [
'multipart' => $requestdata
]);

$data = $response->getBody()->getContents();
$data = json_decode($data, TRUE);

$token = $data['token_type'].' '.$data['access_token'];

return $token;
}

и это мой код в vb.net

     Sub token()

Dim grand_type As String = "client_credentials"
Dim client_id As String = "testclient"
Dim client_secret As String = "abcdefghijklmnopqrstuvwxyz12341234567890"
Dim strHeaders As String
Dim urlAuth As String = "http://abc123.local/authorizations"

strHeaders = String.Format("grant_type={0}&client_id={1}&client_secret={2}",
grand_type, client_id, client_secret)

Dim JSONEncode As String
JSONEncode = JsonConvert.SerializeObject(strHeaders)

Dim byteData As Byte() = Encoding.UTF8.GetBytes(JSONEncode )
Dim httpReq As HttpWebRequest = TryCast(HttpWebRequest.Create(urlAuth), HttpWebRequest)
httpReq.Method = "POST"
httpReq.ContentType = "multipart/form-data"
httpReq.ContentLength = byteData.Length

'-=-=-=-=-=-=-=-= Sample Sending Data -=-=-=-=-=-=-=-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
ServicePointManager.ServerCertificateValidationCallback =
New System.Net.Security.RemoteCertificateValidationCallback(AddressOf AcceptAllCertifications)

Dim reqStream As Stream = httpReq.GetRequestStream()
reqStream.Write(byteData, 0, byteData.Length)

Dim request As WebRequest = WebRequest.Create(urlAuth)
'-=-=-=-=-=-=-=-= Sample Receiving Data -=-=-=-=-=-=-=-=
Dim resStream As Stream = httpReq.GetResponse.GetResponseStream()  
Dim objReader As New StreamReader(resStream, Encoding.UTF8)
Dim wr As WebResponse = httpReq.GetResponse()
Dim receiveStream As Stream = wr.GetResponseStream()
Dim reader As New StreamReader(receiveStream, Encoding.UTF8)
Dim content As String = reader.ReadToEnd()
End Sub


Private Function AcceptAllCertifications(sender As Object, certification As System.Security.Cryptography.X509Certificates.X509Certificate,
chain As System.Security.Cryptography.X509Certificates.X509Chain, sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
Return True
End Function

я получил ошибку для плохого запроса, для этой части:

"Dim resStream As Stream = httpReq.GetResponse.GetResponseStream()"

Есть идеи? благодаря

Теги:
parameters
httpwebrequest
webrequest

1 ответ

0

уже нашел ответ, получил его от http://howtostartprogramming.com/vb-net/vb-net-tutorial-51-httpwebrequest-post-method/

благодаря

Ещё вопросы

Сообщество Overcoder
Наверх
Меню