$key, 'collection' => arr-6ren">
gpt4 book ai didi

c# - 在 VB NET 或 C# 中发布 PHP 数组

转载 作者:太空宇宙 更新时间:2023-11-03 13:32:04 26 4
gpt4 key购买 nike

我在 PHP 中有这段代码

<?php
$key = md5('test123'.date("Y-m-d")."3dgdnk5k1yfw3rpy3r5mi25w2zrtmg");
$fields = array(
'apiID' => 'test123',
'date' => date("Y-m-d") ,
'token' => $key,
'collection' => array(
array(
"ID" => 35,
"fecha" => '2013-11-20',
"hora" => '12:15',
"num" => '36646363463636',
"tipo" => 'multa',
"calle" => 'rivadavia',
"altura" => '450',
"dominio" => 'HDP 123'
) ,
array(
"ID" => 36,
"fecha" => '2013-11-20',
"hora" => '12:16' ,
"num" => '36646363463636',
"tipo" => 'hola',
"calle" => 'mitre',
"altura" => '450',
"dominio" => 'HDP 123'
)
)
);

$postFields = http_build_query($fields, 'flags_');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://testpage.com/api");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields);
$r = curl_exec($curl);
curl_close($curl);

我需要在 VB NET 或 C# 中等效于此请求的代码

到目前为止我在 VB NET 中完成的代码是这样的

Imports System.Net
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Web
Imports System.Security.Cryptography

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim testString As String = "test1232013-11-223dgdnk5k1yfw3rpy3r5mi25w2zrtmg"
Dim asciiBytes As Byte() = ASCIIEncoding.ASCII.GetBytes(testString)
Dim hashedBytes As Byte() = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes)
Dim hashedString As String = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower()

Dim post_values As New Dictionary(Of String, String)
post_values.Add("apiID", "test123")
post_values.Add("date", "2013-11-22")
post_values.Add("token", hashedString) ' The hash MD5
'Here i dont know how to publish the array
post_values.Add("collection", "IDacta=35&fecha=2013-11-20&hora=12:15&num=36646363463636&tipo=multa&calle=alberdi&altura=450&dominio=HDP 123")

Dim post_string As String = ""

For Each post_value As KeyValuePair(Of String, String) In post_values
post_string += post_value.Key + "=" + HttpUtility.UrlEncode(post_value.Value) + "&"
Next

post_string = post_string.TrimEnd("&")

Dim vSolicitud As WebRequest = WebRequest.Create("http://testpage.com/api")
vSolicitud.Proxy = Nothing
vSolicitud.Method = "POST"
vSolicitud.ContentType = "application/x-www-form-urlencoded"

Dim vXML As String = post_string

Dim byteArray As Byte() = Encoding.UTF8.GetBytes(vXML)

vSolicitud.ContentLength = byteArray.Length

Dim dataStream As Stream = vSolicitud.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()

Dim vRespuesta As WebResponse = vSolicitud.GetResponse()
Dim vStream As StreamReader = New StreamReader(vRespuesta.GetResponseStream())

Dim vStr As String = vStream.ReadToEnd().Trim

vRespuesta.Close()
vStream.Close()

TextBox1.Text = vStr

Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

¿ 如何 POST 这些数组值?

提前致谢。

最佳答案

我找到了解决方案,发送这个字符串:

collection[0][IDacta]=35&collection[0][fecha]=2013-11-20&collection[0][hora]=12:15&collection[0][num]=36646363463636&collection[0][tipo]=multa&collection[0][calle]=alberdi&collection[0][altura]=450&collection[0][dominio]=HDP 123&collection[1][IDacta]=36&collection[1][fecha]=2013-11-20&collection[1][hora]=10&collection[1][num]=36646363463636&collection[1][tipo]=multa&collection[1][calle]=alberdi&collection[1][altura]=450&collection[1][dominio]=HDP 123

关于c# - 在 VB NET 或 C# 中发布 PHP 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20149242/

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