文本API集成问题-没有找到错误405页

本文关键字:错误 405页 API 集成 成问题 文本 | 更新日期: 2023-09-27 18:09:28

我正在使用创新短信API网关,这是通过我的错误。

文档可在链接http://www.innovativetxt.com/services/sms_api_gateway.htm,错误发生在我的本地机器上,但在生产服务器上工作正常。

远程服务器返回错误:(405)Method Not Allowed.

在这行代码:

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

try
{
// InnovativeTXT POST URL
string url = "http://innovativetxt.com/cp/api";
// XML-formatted data
string toSender = "4477878585244";
string fromSender = "Test";
string textMessage = "Thanks for Choosing Innovative Text Messaging Solution.";
string fields = "?to=" + toSender + "&from=" + fromSender + "&text=" + textMessage +     "&api_key=xxx&api_secret=xxxxx";
url = url + fields;
// web request start
Uri uri = new Uri(url);
string data = "field-keywords=ASP.NET 2.0";
if (uri.Scheme == Uri.UriSchemeHttp)
{
// create a request on behalf of uri
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);    
// setting parameter for the request
request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
// a stream writer for the request
StreamWriter writer = new StreamWriter(request.GetRequestStream());
// write down the date
writer.Write(data);
//close the stream writer
writer.Close();
// getting response from the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8);
// to write a http response from the characters
Response.Write(readStream.ReadToEnd());
// close the response
response.Close();
// close the reader
readStream.Close();
}
}
catch (Exception exp)
{
// catch for unhelded exception
Response.Write(exp.Message);
}

文本API集成问题-没有找到错误405页

此问题与IIS处理程序映射有关。

你应该在字符串URL的末尾指定文件名:

string url = "http://innovativetxt.com/cp/api/somepage.aspx";

您可以使用默认的页面,如default.aspxindex.php