【发布时间】:2017-07-12 06:39:24
【问题描述】:
我想运行 CURL POST 以通过 Plivo API 服务发送 SMS 消息。
我通过在 C# 中使用 HttpWebRequest 来实现(见下文)。
参数如下: POSTurl = "https://api.plivo.com/v1/Account/MA****************M2/消息/'" JSONRequest == "src=+972545675453&dst=0545675453&text=TEST"
在他们的文档中,我需要使用以下参数: -i --user AUTH_ID:AUTH_TOKEN
我不知道如何实现,但它不起作用(401 错误 - 未经授权)
我尝试在我的代码中使用它而不是 auth 参数,如下所示:
auth == “MA****************MM2:Yj****************************** M5ZjA4"
需要一些建议吗????
谢谢
这是我的代码:
public static SqlString POSTSG(String POSTurl, String auth, SqlString JSONRequest)
{
SqlPipe pipe = SqlContext.Pipe;
//Create Request
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(POSTurl);
myHttpWebRequest.Method = "POST";
myHttpWebRequest.Headers.Add("Authorization", auth);
myHttpWebRequest.ContentType = "application/json; charset=utf-8";
StreamWriter streamWriter = new StreamWriter(myHttpWebRequest.GetRequestStream(), System.Text.Encoding.UTF8);
streamWriter.Write(JSONRequest);
streamWriter.Flush();
streamWriter.Close();
// Get the response
HttpWebResponse httpResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Create a new read stream for the response body and read it
StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream());
SqlString result = streamReader.ReadToEnd();
return (result);
}
【问题讨论】:
-
最好的方法是在没有应用程序的情况下发送消息,然后使用像wireshark或fiddler这样的嗅探器跟踪消息。你会学到很多东西。然后修改您的代码以发送与没有您的应用程序相同的代码。
标签: c# curl httpwebrequest plivo