php to vb.net උදවු

hirugalbandara

Well-known member
  • Sep 24, 2014
    3,705
    1,980
    113
    සිරිකොත

    මේ php එක vb.net වලට ලියන්නේ කොහොමද​

    date_default_timezone_set('Asia/Colombo');
    $now=date("Y-m-d\TH:i:s");
    $username="username";
    $password="passwoard";
    $digest=md5($password);

    $body='{

    "messages":[
    {

    "number": "ghgy",
    "mask": "abc",
    "text": "This test",
    "campaignName":"abc12" }

    ]


    }';



    $ch=curl_init();

    curl_setopt($ch,CURLOPT_URL,"https://....................");
    curl_setopt($ch,CURLOPT_POST,1);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$body);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

    $headers=[
    'content-Type:application/json',
    'user:'.$username,
    'digest:'.$dige5st,
    'created:'.$now

    ];

    curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    $server_output=curl_exec($ch);

    curl_close($ch);
    var_dump($server_output);
     

    charith84

    Well-known member
  • Jun 22, 2006
    10,397
    7,412
    113
    VB කරන්නෙහ් ඇයි බ0 ? C# වලින් කරපන්කො
    C# වලින් ඔනි නම් දෙන්නම්
     
    • Like
    Reactions: hirugalbandara

    charith84

    Well-known member
  • Jun 22, 2006
    10,397
    7,412
    113
    Code:
       Public Sub JasonWebRequest()
            ' Declarations
            Dim username As String = "charith84"
            Dim usrpass As String = "password"
            Dim postStr As String = "{""messages"" : [{""number"": ""ghgy"",""mask"": ""abc"",""text"": ""This test"",""campaignName"":""abc12"" }]}';"
            Dim pwHash As String = Nothing
            Dim timeNow = TimeZoneInfo.ConvertTime(Now, TimeZoneInfo.FindSystemTimeZoneById("Sri Lanka Standard Time"))
            ' Creating Md5 Hash
            Using hash As Security.Cryptography.MD5 = Security.Cryptography.MD5.Create()
                Dim strHash As Text.StringBuilder = New System.Text.StringBuilder
                Dim pwBytes() As Byte = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(usrpass))
                For bIndex As Integer = 0 To pwBytes.Length - 1
                    strHash.Append(pwBytes(bIndex).ToString("X2"))
                Next bIndex
                pwHash = strHash.ToString
            End Using
            ' Creating WebRequest
            Dim request As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create("http://www.elakiri.com"), Net.HttpWebRequest)
            Dim postBytes() = System.Text.Encoding.UTF8.GetBytes(postStr)
            With request
                .Method = Net.WebRequestMethods.Http.Post
                .KeepAlive = True
                .UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
                .ContentType = "application/json"
                .ContentLength = postBytes.Length
                .Headers("user") = username
                .Headers("digest") = pwHash
                .Headers("create") = timeNow.ToString("y-m-d\\h:m:s")
            End With
            Dim reqStream As IO.Stream = request.GetRequestStream()
            reqStream.Write(postBytes, 0, postBytes.Length)
            reqStream.Close()
            Dim response As Net.HttpWebResponse = DirectCast(request.GetResponse(), Net.HttpWebResponse)
            Using sread As New IO.StreamReader(response.GetResponseStream())
                Dim responsestr As String = sread.ReadToEnd
                MsgBox(responsestr.Length)
            End Using
        End Sub
     

    hirugalbandara

    Well-known member
  • Sep 24, 2014
    3,705
    1,980
    113
    සිරිකොත
    Code:
       Public Sub JasonWebRequest()
            ' Declarations
            Dim username As String = "charith84"
            Dim usrpass As String = "password"
            Dim postStr As String = "{""messages"" : [{""number"": ""ghgy"",""mask"": ""abc"",""text"": ""This test"",""campaignName"":""abc12"" }]}';"
            Dim pwHash As String = Nothing
            Dim timeNow = TimeZoneInfo.ConvertTime(Now, TimeZoneInfo.FindSystemTimeZoneById("Sri Lanka Standard Time"))
            ' Creating Md5 Hash
            Using hash As Security.Cryptography.MD5 = Security.Cryptography.MD5.Create()
                Dim strHash As Text.StringBuilder = New System.Text.StringBuilder
                Dim pwBytes() As Byte = hash.ComputeHash(System.Text.Encoding.UTF8.GetBytes(usrpass))
                For bIndex As Integer = 0 To pwBytes.Length - 1
                    strHash.Append(pwBytes(bIndex).ToString("X2"))
                Next bIndex
                pwHash = strHash.ToString
            End Using
            ' Creating WebRequest
            Dim request As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create("http://www.elakiri.com"), Net.HttpWebRequest)
            Dim postBytes() = System.Text.Encoding.UTF8.GetBytes(postStr)
            With request
                .Method = Net.WebRequestMethods.Http.Post
                .KeepAlive = True
                .UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
                .ContentType = "application/json"
                .ContentLength = postBytes.Length
                .Headers("user") = username
                .Headers("digest") = pwHash
                .Headers("create") = timeNow.ToString("y-m-d\\h:m:s")
            End With
            Dim reqStream As IO.Stream = request.GetRequestStream()
            reqStream.Write(postBytes, 0, postBytes.Length)
            reqStream.Close()
            Dim response As Net.HttpWebResponse = DirectCast(request.GetResponse(), Net.HttpWebResponse)
            Using sread As New IO.StreamReader(response.GetResponseStream())
                Dim responsestr As String = sread.ReadToEnd
                MsgBox(responsestr.Length)
            End Using
        End Sub

    maru sahooooo.
    poddak ahemeha karala wade goda da gaththa.
    godak pin machooo