Question Send JSON Encoded Array via HTTP Request

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Hey everyone..I have an array which I've json encoded, for example:
["item1","item2","item3"]

Somehow, I now need to send this JSON encoded request along with my request URL so I can get the response. However, I'm not really sure how to do this. In one example i've found, they are doing such a thing - but in PHP..This is what they are showing

VB.NET:
$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;

// Put your URLS into an array and json_encode them.
$batchedDomains = array('www.moz.com', 'www.apple.com', 'www.pizza.com');
$encodedDomains = json_encode($batchedDomains);

// We can easily use Curl to send off our request.
// Note that we send our encoded list of domains through curl's POSTFIELDS.
$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => $encodedDomains
);

$ch = curl_init($requestUrl);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close( $ch );

$contents = json_decode($content);
print_r($contents);

Does anyone have any suggestions how this might be done in VB.net? Do I need a special class to send CURL postfields? Is there an easier way to do this than using Postfields? Thank you!

VB.NET:
        For i = 0 To Integer.MaxValue
            Dim page = Me.txtDomains.Lines.Cast(Of String).Skip(i * 10).Take(10).ToArray()

            If page.Length = 0 Then
                Exit For
            End If

            'json encode the array
            Dim JSONEncode As String
            JSONEncode = JsonConvert.SerializeObject(page)
            MsgBox(JSONEncode)
        Next
 

Similar threads

Back
Top