 |
|
มีใครส่ง sms โดยใช้ rest api แล้วทางผู้ให้บริการส่งข้อมูลมาแบบนี้
Code
POST /sms/1/text/single HTTP/1.1
Host : yourhost
Authorization: Basic tokenkey
Content-Type: application/json
{
"from":"sender",
"to":[ "66911996652" ],
"text":"test sms",
}
เขาให้มาแบบนี้ ผมใช้ vb.net
พอทำไปมี response เป็น bad request 400
โค๊ดผมแบบนี้
Code (VB.Net)
System.Net.ServicePointManager.Expect100Continue = False
System.Net.ServicePointManager.UseNagleAlgorithm = False
Dim RQ = DirectCast(System.Net.WebRequest.Create("yourhost"), System.Net.HttpWebRequest)
Dim postData As String = String.Format("from:{0}", "sender", "to:{1}", "66911996652", "text:{2}", "test sms")
Dim data = System.Text.Encoding.UTF8.GetBytes(postData)
With RQ
.Method = "POST"
.ContentType = "application/json"
.ContentLength = data.Length
.Headers.Add("Authorization", "Basic " & Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("username:password")))
.AllowWriteStreamBuffering = True
.KeepAlive = False
.Credentials = System.Net.CredentialCache.DefaultCredentials
End With
Using stream = RQ.GetRequestStream()
stream.Write(data, 0, data.Length)
End Using
Dim response = DirectCast(RQ.GetResponse(), System.Net.HttpWebResponse) --> error บรรทัดนี้ครับ
Dim responseString = New System.IO.StreamReader(response.GetResponseStream()).ReadToEnd()
แก้ไขยังไงครับ
Tag : .NET
|
|
 |
 |
 |
 |
Date :
2019-03-04 16:56:29 |
By :
nattawutxp |
View :
2234 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |