Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strRecipient As String = "0819871234"
Dim strSMSAccount As String = "user"
Dim strSMSPassword As String = "pass"
Dim strLang As String = "T"
Dim strMessage As String = "ทดสอบการส่งข้อความผ่านระบบ API"
Dim strMessageX As String = Server.UrlEncode(strMessage)
Dim strData As String = "msisdn=" & strRecipient & "&user=" & strSMSAccount & "&pass=" & strSMSPassword & "&lang=" & strLang & "&msg=" & strMessageX
Dim xmlHTTP As Object = CreateObject("MSXML2.ServerXMLHTTP")
xmlHTTP.Open("POST", "http://smsgateway.applymail.com/api/send.php", False)
xmlHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xmlHTTP.SetRequestHeader("Content-Length", Len(strData))
xmlHTTP.SetRequestHeader("Connection", "close")
xmlHTTP.Send(strData)
Dim strReturn As String = xmlHTTP.ResponseText
xmlHTTP = Nothing
Dim a() As String
Dim status() As String
Dim detail() As String
a = Split(strReturn, "<STATUS>")
status = Split(a(1), "</STATUS>")
If status(0) = "OK" Then
Response.Write("ส่งสำเร็จ")
Else
a = Split(strReturn, "<DETAIL>")
detail = Split(a(1), "</DETAIL>")
Response.Write("ส่งไม่สำเร็จ เนื่องจาก " & detail(0))
End If
End Sub
End Class
ไม่รู้เกี่ยวมั้ย นะครับ แต่ว่าได้ยางไงแล้ว ช่วย มา post code ให้ดูกันบ้างนะครับ
เพราะว่าผมก็จะทำเหมือนกันเลยครับแต่ว่าผมใช้ .net ครับ vb or c# ได้หมด อิๆๆ ขอบคุณครับ
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();