VB.NET 通过 HTTP 发布;构建 PHP 查询
VB.NET Posting via HTTP; Build PHP Query
我正在尝试制作一个 post 网站,该网站使用以下模板:
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://api.upcdatabase.org/submit/curl.php',
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => http_build_query(array(
'upc' => '0000000000000',
'mrsp' => '0.00',
'apikey' => 'YOUR_API_KEY_GOES_HERE',
'title' => 'Title of product',
'alias' => 'Title alias',
'description' => 'Optional lengthy description of product.',
'unit' => 'Per case'
))));
$server_output = curl_exec($ch);
curl_close($ch);
我发现这个网站可以帮助形成 POST。
如何使用变量 upc、mrsp、apikey、title... 等查询数组,以便我可以 post 将其发送到网站?
您的主要问题可能是您的 post 数据使用逗号而不是符号作为分隔符。此代码有效,我得到 "OK" 响应:
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
Dim req As WebRequest = WebRequest.Create("http://api.upcdatabase.org/submit/curl.php")
req.Method = "POST"
Dim http As HttpWebRequest = DirectCast(req, HttpWebRequest)
http.ContentType = "application/x-www-form-urlencoded"
Dim postData As String = "upc=0111222333449&apikey=YOU_CANT_SEE_MY_KEY&title=TOMATO SAUCE&description=TOMATO SAUCE&mrsp=1.23&unit=Per Case"
Dim requestBytes As Byte() = Encoding.UTF8.GetBytes(postData)
req.ContentLength = requestBytes.Length
Dim reqStream As System.IO.Stream = http.GetRequestStream()
reqStream.Write(requestBytes, 0, requestBytes.Length)
reqStream.Close()
Dim response As WebResponse = http.GetResponse()
Dim respStream As System.IO.Stream = response.GetResponseStream()
Dim rdr As System.IO.StreamReader = New IO.StreamReader(respStream)
Dim status As String = rdr.ReadToEnd()
Console.WriteLine(status)
Console.ReadKey()
End Sub
End Module
我正在尝试制作一个 post 网站,该网站使用以下模板:
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://api.upcdatabase.org/submit/curl.php',
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => http_build_query(array(
'upc' => '0000000000000',
'mrsp' => '0.00',
'apikey' => 'YOUR_API_KEY_GOES_HERE',
'title' => 'Title of product',
'alias' => 'Title alias',
'description' => 'Optional lengthy description of product.',
'unit' => 'Per case'
))));
$server_output = curl_exec($ch);
curl_close($ch);
我发现这个网站可以帮助形成 POST。
如何使用变量 upc、mrsp、apikey、title... 等查询数组,以便我可以 post 将其发送到网站?
您的主要问题可能是您的 post 数据使用逗号而不是符号作为分隔符。此代码有效,我得到 "OK" 响应:
Imports System.Net
Imports System.Text
Module Module1
Sub Main()
Dim req As WebRequest = WebRequest.Create("http://api.upcdatabase.org/submit/curl.php")
req.Method = "POST"
Dim http As HttpWebRequest = DirectCast(req, HttpWebRequest)
http.ContentType = "application/x-www-form-urlencoded"
Dim postData As String = "upc=0111222333449&apikey=YOU_CANT_SEE_MY_KEY&title=TOMATO SAUCE&description=TOMATO SAUCE&mrsp=1.23&unit=Per Case"
Dim requestBytes As Byte() = Encoding.UTF8.GetBytes(postData)
req.ContentLength = requestBytes.Length
Dim reqStream As System.IO.Stream = http.GetRequestStream()
reqStream.Write(requestBytes, 0, requestBytes.Length)
reqStream.Close()
Dim response As WebResponse = http.GetResponse()
Dim respStream As System.IO.Stream = response.GetResponseStream()
Dim rdr As System.IO.StreamReader = New IO.StreamReader(respStream)
Dim status As String = rdr.ReadToEnd()
Console.WriteLine(status)
Console.ReadKey()
End Sub
End Module