我正在使用Innovative Text SMS API网关,这是通过我的错误。
文档可以在链接http://www.innovativetxt.com/services/sms_api_gateway.htm上找到 ,错误发生在我的本地计算机上,但在生产服务器上运行正常。
远程服务器返回错误:(405)方法不允许。
在这行代码:
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); }I am using Innovative Text SMS API gateway which is through me error.
Documentation is available at link http://www.innovativetxt.com/services/sms_api_gateway.htm, the error is happening on my local machine, but works fine at the production server.
The remote server returned an error: (405) Method Not Allowed.
at this line of code:
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); }最满意答案
此问题与IIS处理程序映射有关。
您应该在字符串URL的末尾指定文件名:
string url = "http://innovativetxt.com/cp/api/somepage.aspx";您可以使用默认页面,如default.aspx或index.php等...
This issue relates to IIS Handler mappings.
You should specify the file name at the end of string URL:
string url = "http://innovativetxt.com/cp/api/somepage.aspx";You can use default pages like, default.aspx or index.php etc...
更多推荐
发布评论