0

我正在使用通过我错误的创新文本 SMS 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);
}
4

1 回答 1

0

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

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

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

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

于 2013-04-17T07:29:15.923 回答