I know I'm getting a valid response back from this thrid party API that I made the request to because I can plug in the URL that my request sent to the 3rd party REST API server manually and I get a valud response back in XML in the browser. However for
some reason besides the fact that I see a valid response while testing the request URL manually that my code produced (while debugging through it), I still get a 500 error on GetResponse():
public static HttpWebResponse SendRequest(HttpWebRequest request)
{
HttpWebResponse response;
request.Timeout = 30000;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] requestBytes = Encoding.UTF8.GetBytes(request.ToString());
request.ContentLength = requestBytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
}
response = (HttpWebResponse)request.GetResponse(); // I get error: The remote server returned an error: (500) Internal Server Error.
if (response == null)
throw new NullReferenceException("Response received was null");
return response;
}
If the remote server is no longer complaining about my request and I'm getting what seems to be a valid value back from their API, then why all the fuss by the GetResponse method still? I'm testing this over localhost but that should not matter.
Below are a few examples you might want to try... did a little cutting/pasting and didn't try to compile, but should work fine. Wrote these methods a few years ago and have been working fine since.
public class HttpPost
{
static public string GetResponseAsString( string url, int timeout )
{
HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create( url );
webRequest.AllowAutoRedirect = true;
webRequest.Timeout = 1000 * 30;
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
webRequest.PreAuthenticate = true;
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.Proxy = new System.Net.WebProxy("your proxy server", true); // comment out if you're not going thru a proxy
WebResponse webResponse = null;
try
{
webResponse = webRequest.GetResponse();
Stream stream = webResponse.GetResponseStream();
Encoding encoding = System.Text.Encoding.GetEncoding( "utf-8" );
StreamReader streamReader = new StreamReader( stream, encoding );
string result = streamReader.ReadToEnd();
return result;
}
catch ( Exception e )
{
return e.Message;
}
}
static public HttpWebResponse GetResponse(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Proxy = new System.Net.WebProxy("your proxy server", true); // comment out if you're not going thru a proxy
webRequest.AllowAutoRedirect = true;
webRequest.Timeout = 1000 * 30;
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
webRequest.PreAuthenticate = true;
webRequest.Credentials = CredentialCache.DefaultCredentials;
return (HttpWebResponse)webRequest.GetResponse();
}
}
http post
Please mark the post as ANSWER if it helps you
Disclaimer: Just my opinion. Not my employer or anyone else....
Here's the thing, we've use the code I posted before in another non-related app of ours. We can do it testing over localhost as well. So why the heck can't I receive the response without getting a 500 error in this one over localhost after sending the
web request to the 3rd party API when the browser is showing me (when you past in the request in the url for testing in the browser) that I'm getting back a valid API response/SOAP message from the 3rd party REST API? I don't know that I really need any
authentication properties here like PreAuthenticate, credentials, etc. I've tried them and they do not make any difference to getting through to successfully grabbing back the response here without getting the 500 error. I've also seen another framework
use the same request properties and same syntax to receive the response successfully. But not sure if they were testing over localhost.
Keep in mind I'm running this via localhost on a Vista PC so IIS 7. I've tried both using just plain localhost as well as the VS web server for localhost:port.
here's the request / reponse being sent over the wire:
Not sure if you have figured out the solution for this particular case. One thing i can suggest can you please check whether this 3rd party API accept request only in Get method.In that case use
request.Method = "GET";
instead of
request.Method = "POST";
Thanks
Marked as answer by espresso on Jan 22, 2009 08:31 PM
IIS Diagnostics Output
Url: http://localhost:80/xxxx.aspx
Site: 3
App Pool: DefaultAppPool
Process: 992
Authentication: anonymous
User from token: xxxx\xxxx$
Activity ID: {00000000-0000-0000-1600-0080020000FC}
Failure Reason: STATUS_CODE
Final Status: 500
Time Taken: 514 msec
IIS Trace Detail Highlights
No. EventName Details Time
81. n n r MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo="" 17:44:45.056
IIS Trace Detail
No. EventName Details Time
1. n n i GENERAL_REQUEST_START SiteId="3", AppPoolId="DefaultAppPool", ConnId="59594576", RawConnId="59594584", RequestURL="http://localhost:80/xxxx.aspx", RequestVerb="POST" 17:44:44.542
2. n n i FILTER_START FilterName="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_filter.dll" 17:44:44.542
3. n n i FILTER_PREPROC_HEADERS_START 17:44:44.542
4. n n i FILTER_SET_REQ_HEADER HeaderName="AspFilterSessionId:", HeaderValue="" 17:44:44.542
5. n n i FILTER_PREPROC_HEADERS_END 17:44:44.542
6. n n i FILTER_END 17:44:44.542
7. n n i URL_CACHE_ACCESS_START RequestURL="/xxxx.aspx" 17:44:44.542
8. n n i URL_CACHE_ACCESS_END PhysicalPath="", URLInfoFromCache="true", URLInfoAddedToCache="false", ErrorCode="The operation completed successfully. (0x0)" 17:44:44.542
9. n n i GENERAL_GET_URL_METADATA PhysicalPath="C:\www\xxx\xxxb\xxx\xxx.aspx", AccessPerms="513" 17:44:44.542
10. n n NOTIFY_MODULE_START ModuleName="RequestFilteringModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
11. n n NOTIFY_MODULE_END ModuleName="RequestFilteringModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
12. n n NOTIFY_MODULE_START ModuleName="RequestMonitorModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
13. n n NOTIFY_MODULE_END ModuleName="RequestMonitorModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
14. n n NOTIFY_MODULE_START ModuleName="ConfigurationValidationModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
15. n n NOTIFY_MODULE_END ModuleName="ConfigurationValidationModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
16. n n NOTIFY_MODULE_START ModuleName="IpRestrictionModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
17. n n NOTIFY_MODULE_END ModuleName="IpRestrictionModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
18. n n NOTIFY_MODULE_START ModuleName="FailedRequestsTracingModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
19. n n NOTIFY_MODULE_END ModuleName="FailedRequestsTracingModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
20. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
21. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
22. n n NOTIFY_MODULE_START ModuleName="BasicAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
23. n n i AUTH_START AuthTypeSupported="Basic" 17:44:44.542
24. n n i AUTH_END 17:44:44.542
25. n n NOTIFY_MODULE_END ModuleName="BasicAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
26. n n NOTIFY_MODULE_START ModuleName="WindowsAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
27. n n i AUTH_START AuthTypeSupported="NT" 17:44:44.542
28. n n i AUTH_END 17:44:44.542
29. n n NOTIFY_MODULE_END ModuleName="WindowsAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
30. n n NOTIFY_MODULE_START ModuleName="WindowsAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
31. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
32. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
33. n n NOTIFY_MODULE_COMPLETION ModuleName="WindowsAuthentication", Notification="AUTHENTICATE_REQUEST", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
34. n n NOTIFY_MODULE_START ModuleName="CertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
35. n n i AUTH_START AuthTypeSupported="MapCliCert" 17:44:44.542
36. n n i AUTH_END 17:44:44.542
37. n n NOTIFY_MODULE_END ModuleName="CertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
38. n n NOTIFY_MODULE_START ModuleName="DigestAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
39. n n i AUTH_START AuthTypeSupported="Digest" 17:44:44.542
40. n n i AUTH_END 17:44:44.542
41. n n NOTIFY_MODULE_END ModuleName="DigestAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
42. n n NOTIFY_MODULE_START ModuleName="IISCertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
43. n n i AUTH_START AuthTypeSupported="MapCliCert" 17:44:44.542
44. n n i AUTH_END 17:44:44.542
45. n n NOTIFY_MODULE_END ModuleName="IISCertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
46. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
47. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
48. n n NOTIFY_MODULE_START ModuleName="AnonymousAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
49. n n i AUTH_START AuthTypeSupported="Anonymous" 17:44:44.542
50. n n i AUTH_REQUEST_AUTH_TYPE RequestAuthType="Anonymous" 17:44:44.542
51. n n i AUTH_SUCCEEDED AuthType="3", NTLMUsed="false", RemoteUserName="", AuthUserName="", TokenImpersonationLevel="ImpersonationDelegate" 17:44:44.542
52. n n i AUTH_END 17:44:44.542
53. n n NOTIFY_MODULE_END ModuleName="AnonymousAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
54. n n NOTIFY_MODULE_START ModuleName="DefaultAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="true", fIsCompletion="false" 17:44:44.542
55. n n NOTIFY_MODULE_END ModuleName="DefaultAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="true", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
56. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
57. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
58. n n NOTIFY_MODULE_START ModuleName="UrlAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
59. n n NOTIFY_MODULE_END ModuleName="UrlAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
60. n n NOTIFY_MODULE_START ModuleName="FileAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
61. n n NOTIFY_MODULE_END ModuleName="FileAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
62. n n NOTIFY_MODULE_START ModuleName="UrlAuthorizationModule", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
63. n n NOTIFY_MODULE_END ModuleName="UrlAuthorizationModule", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
64. n n NOTIFY_MODULE_START ModuleName="HttpCacheModule", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
65. n n NOTIFY_MODULE_END ModuleName="HttpCacheModule", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
66. n n NOTIFY_MODULE_START ModuleName="OutputCache", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
67. n n NOTIFY_MODULE_END ModuleName="OutputCache", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
68. n n NOTIFY_MODULE_START ModuleName="StaticCompressionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
69. n n NOTIFY_MODULE_END ModuleName="StaticCompressionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
70. n n NOTIFY_MODULE_START ModuleName="HttpRedirectionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
71. n n NOTIFY_MODULE_END ModuleName="HttpRedirectionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
72. n n NOTIFY_MODULE_START ModuleName="ManagedPipelineHandler", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
73. n n NOTIFY_MODULE_END ModuleName="ManagedPipelineHandler", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
74. n n NOTIFY_MODULE_START ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
75. n n NOTIFY_MODULE_END ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
76. n n NOTIFY_MODULE_START ModuleName="Profile", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
77. n n NOTIFY_MODULE_END ModuleName="Profile", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
78. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="true", fIsCompletion="false" 17:44:44.542
79. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="true", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
80. n n NOTIFY_MODULE_START ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
81. n n r MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo="" 17:44:45.056
82. n n NOTIFY_MODULE_END ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_FINISH_REQUEST" 17:44:45.056
83. n n NOTIFY_MODULE_START ModuleName="AspNetFilterModule", Notification="LOG_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
84. n n NOTIFY_MODULE_END ModuleName="AspNetFilterModule", Notification="LOG_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
85. n n NOTIFY_MODULE_START ModuleName="CustomLoggingModule", Notification="LOG_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
86. n n NOTIFY_MODULE_END ModuleName="CustomLoggingModule", Notification="LOG_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
87. n n NOTIFY_MODULE_START ModuleName="RequestMonitorModule", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
88. n n NOTIFY_MODULE_END ModuleName="RequestMonitorModule", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
89. n n NOTIFY_MODULE_START ModuleName="Session", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
90. n n NOTIFY_MODULE_END ModuleName="Session", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
91. n n NOTIFY_MODULE_START ModuleName="Profile", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
92. n n NOTIFY_MODULE_END ModuleName="Profile", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
93. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
94. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
95. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
96. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
97. n n NOTIFY_MODULE_START ModuleName="DigestAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
98. n n NOTIFY_MODULE_END ModuleName="DigestAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
99. n n NOTIFY_MODULE_START ModuleName="DynamicCompressionModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
100. n n i DYNAMIC_COMPRESSION_START 17:44:45.056
101. n n i DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="NOT_SUCCESS_STATUS" 17:44:45.056
102. n n i DYNAMIC_COMPRESSION_END 17:44:45.056
103. n n NOTIFY_MODULE_END ModuleName="DynamicCompressionModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
104. n n NOTIFY_MODULE_START ModuleName="WindowsAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
105. n n NOTIFY_MODULE_END ModuleName="WindowsAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
106. n n NOTIFY_MODULE_START ModuleName="HttpLoggingModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
107. n n NOTIFY_MODULE_END ModuleName="HttpLoggingModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
108. n n NOTIFY_MODULE_START ModuleName="IsapiModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
109. n n NOTIFY_MODULE_END ModuleName="IsapiModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
110. n n NOTIFY_MODULE_START ModuleName="BasicAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
111. n n NOTIFY_MODULE_END ModuleName="BasicAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
112. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
113. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
114. n n NOTIFY_MODULE_START ModuleName="ProtocolSupportModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
115. n n NOTIFY_MODULE_END ModuleName="ProtocolSupportModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
116. n n NOTIFY_MODULE_START ModuleName="CustomErrorModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
117. n n NOTIFY_MODULE_END ModuleName="CustomErrorModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
118. n n i HTTPSYS_CACHEABLE HttpsysCacheable="false", Reason="VERB_NOT_GET" 17:44:45.056
119. n n i GENERAL_FLUSH_RESPONSE_START 17:44:45.056
120. n n i GENERAL_FLUSH_RESPONSE_END BytesSent="6141", ErrorCode="The operation completed successfully. (0x0)" 17:44:45.056
121. n n i GENERAL_REQUEST_END BytesSent="6141", BytesReceived="769", HttpStatus="500", HttpSubStatus="0" 17:44:45.056
Server Error in '/' Application.
The remote server returned an error: (500) Internal Server Error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
Source Error:
Line 50: requestStream.Close();
Line 51: }
Line 52:
Line 53: response = (HttpWebResponse)request.GetResponse();
Entire problem was I needed to use GET. When sending a request out (Whether it's a SOAP message or just a url request to a 3rd party API), you use GET because you want to get the response back. Otherwise POST is used the other way around, if you were
the SOA framework and exposed your API, you'd want to take what's coming in (request) and process it....then you'd use POST.
as I'm not sending a SOAP message, I am not sure what those lines woudl be used for. I got them from some other code that worked in the past for a similar kind of call to the same API provider.
Congrads on getting it resolved! As for your GET/POST definitions, it's not quite correct. The difference is that in GET, the name/value pairs are in the URL, where as POST embeds them in the http request. There are reasons to use both in both situations.
Anyway, glad you got it fixed.
Please mark the post as ANSWER if it helps you
Disclaimer: Just my opinion. Not my employer or anyone else....
when I use HttpWebRequest.GetResponse() it throws error 500.
I can also say for sure that the request never reaches an invoked webmethod of the webservice since I perform it localy and debugger never stops in that method.
however adding a webreference and invoking its methods like Serive.Method() works fine.
I'm also 100% sure that XML I post is correct.
Please don't ask why do I use GetResponse if I can just add a reference.. I just have my reasons for that.
the question is why does it works with one webservice and throws 500th error with the other located on the very same machine.
espresso
Member
80 Points
387 Posts
HttpWebRequest.GetResponse() throwing 500 error
Jan 20, 2009 03:03 AM|LINK
I know I'm getting a valid response back from this thrid party API that I made the request to because I can plug in the URL that my request sent to the 3rd party REST API server manually and I get a valud response back in XML in the browser. However for some reason besides the fact that I see a valid response while testing the request URL manually that my code produced (while debugging through it), I still get a 500 error on GetResponse():
public static HttpWebResponse SendRequest(HttpWebRequest request) { HttpWebResponse response; request.Timeout = 30000; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; byte[] requestBytes = Encoding.UTF8.GetBytes(request.ToString()); request.ContentLength = requestBytes.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); } response = (HttpWebResponse)request.GetResponse(); // I get error: The remote server returned an error: (500) Internal Server Error. if (response == null) throw new NullReferenceException("Response received was null"); return response; }If the remote server is no longer complaining about my request and I'm getting what seems to be a valid value back from their API, then why all the fuss by the GetResponse method still? I'm testing this over localhost but that should not matter.Rick Matthys
Contributor
2794 Points
406 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 21, 2009 05:44 AM|LINK
Below are a few examples you might want to try... did a little cutting/pasting and didn't try to compile, but should work fine. Wrote these methods a few years ago and have been working fine since.
public class HttpPost { static public string GetResponseAsString( string url, int timeout ) { HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create( url ); webRequest.AllowAutoRedirect = true; webRequest.Timeout = 1000 * 30; webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; webRequest.PreAuthenticate = true; webRequest.Credentials = CredentialCache.DefaultCredentials;http post
Disclaimer: Just my opinion. Not my employer or anyone else....
espresso
Member
80 Points
387 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 04:25 PM|LINK
Thanks for the example.
Here's the thing, we've use the code I posted before in another non-related app of ours. We can do it testing over localhost as well. So why the heck can't I receive the response without getting a 500 error in this one over localhost after sending the web request to the 3rd party API when the browser is showing me (when you past in the request in the url for testing in the browser) that I'm getting back a valid API response/SOAP message from the 3rd party REST API? I don't know that I really need any authentication properties here like PreAuthenticate, credentials, etc. I've tried them and they do not make any difference to getting through to successfully grabbing back the response here without getting the 500 error. I've also seen another framework use the same request properties and same syntax to receive the response successfully. But not sure if they were testing over localhost.
espresso
Member
80 Points
387 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 04:42 PM|LINK
Keep in mind I'm running this via localhost on a Vista PC so IIS 7. I've tried both using just plain localhost as well as the VS web server for localhost:port.
here's the request / reponse being sent over the wire:
POST /xxxxxx.aspx HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/xxxxx.aspx
Content-Type: application/x-www-form-urlencoded
Content-Length: 249
__VIEWSTATE=%2FwEPDwUKLTEwNjg4NTM5OGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFDmJ0bkxvZ2luQnV0dG9uejCq%2FmxnC032x2Pvh7Yu8vXJwm4%3D&__EVENTVALIDATION=%2FwEWAgKj8tnxBAKR2da8DAJkTWCYFwyhYjDbsPvNqaUBw%2BY5&btnLoginButton.x=41&btnLoginButton.y=14
HTTP/1.x 500 Internal Server Error
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 22 Jan 2009 17:38:41 GMT
Content-Length: 5901
rkzico
Member
62 Points
12 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 04:47 PM|LINK
Not sure if you have figured out the solution for this particular case. One thing i can suggest can you please check whether this 3rd party API accept request only in Get method.In that case use
instead of
request.Method = "POST";espresso
Member
80 Points
387 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 05:06 PM|LINK
They are definitely expecting a POST.
Also, here is the error trace from IIS 7
IIS Diagnostics Output
Url: http://localhost:80/xxxx.aspx
Site: 3
App Pool: DefaultAppPool
Process: 992
Authentication: anonymous
User from token: xxxx\xxxx$
Activity ID: {00000000-0000-0000-1600-0080020000FC}
Failure Reason: STATUS_CODE
Final Status: 500
Time Taken: 514 msec
IIS Trace Detail Highlights
No. EventName Details Time
81. n n r MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo="" 17:44:45.056
IIS Trace Detail
No. EventName Details Time
1. n n i GENERAL_REQUEST_START SiteId="3", AppPoolId="DefaultAppPool", ConnId="59594576", RawConnId="59594584", RequestURL="http://localhost:80/xxxx.aspx", RequestVerb="POST" 17:44:44.542
2. n n i FILTER_START FilterName="C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet_filter.dll" 17:44:44.542
3. n n i FILTER_PREPROC_HEADERS_START 17:44:44.542
4. n n i FILTER_SET_REQ_HEADER HeaderName="AspFilterSessionId:", HeaderValue="" 17:44:44.542
5. n n i FILTER_PREPROC_HEADERS_END 17:44:44.542
6. n n i FILTER_END 17:44:44.542
7. n n i URL_CACHE_ACCESS_START RequestURL="/xxxx.aspx" 17:44:44.542
8. n n i URL_CACHE_ACCESS_END PhysicalPath="", URLInfoFromCache="true", URLInfoAddedToCache="false", ErrorCode="The operation completed successfully. (0x0)" 17:44:44.542
9. n n i GENERAL_GET_URL_METADATA PhysicalPath="C:\www\xxx\xxxb\xxx\xxx.aspx", AccessPerms="513" 17:44:44.542
10. n n NOTIFY_MODULE_START ModuleName="RequestFilteringModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
11. n n NOTIFY_MODULE_END ModuleName="RequestFilteringModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
12. n n NOTIFY_MODULE_START ModuleName="RequestMonitorModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
13. n n NOTIFY_MODULE_END ModuleName="RequestMonitorModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
14. n n NOTIFY_MODULE_START ModuleName="ConfigurationValidationModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
15. n n NOTIFY_MODULE_END ModuleName="ConfigurationValidationModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
16. n n NOTIFY_MODULE_START ModuleName="IpRestrictionModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
17. n n NOTIFY_MODULE_END ModuleName="IpRestrictionModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
18. n n NOTIFY_MODULE_START ModuleName="FailedRequestsTracingModule", Notification="BEGIN_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
19. n n NOTIFY_MODULE_END ModuleName="FailedRequestsTracingModule", Notification="BEGIN_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
20. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
21. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
22. n n NOTIFY_MODULE_START ModuleName="BasicAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
23. n n i AUTH_START AuthTypeSupported="Basic" 17:44:44.542
24. n n i AUTH_END 17:44:44.542
25. n n NOTIFY_MODULE_END ModuleName="BasicAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
26. n n NOTIFY_MODULE_START ModuleName="WindowsAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
27. n n i AUTH_START AuthTypeSupported="NT" 17:44:44.542
28. n n i AUTH_END 17:44:44.542
29. n n NOTIFY_MODULE_END ModuleName="WindowsAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
30. n n NOTIFY_MODULE_START ModuleName="WindowsAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
31. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
32. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="MAP_PATH", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
33. n n NOTIFY_MODULE_COMPLETION ModuleName="WindowsAuthentication", Notification="AUTHENTICATE_REQUEST", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
34. n n NOTIFY_MODULE_START ModuleName="CertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
35. n n i AUTH_START AuthTypeSupported="MapCliCert" 17:44:44.542
36. n n i AUTH_END 17:44:44.542
37. n n NOTIFY_MODULE_END ModuleName="CertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
38. n n NOTIFY_MODULE_START ModuleName="DigestAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
39. n n i AUTH_START AuthTypeSupported="Digest" 17:44:44.542
40. n n i AUTH_END 17:44:44.542
41. n n NOTIFY_MODULE_END ModuleName="DigestAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
42. n n NOTIFY_MODULE_START ModuleName="IISCertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
43. n n i AUTH_START AuthTypeSupported="MapCliCert" 17:44:44.542
44. n n i AUTH_END 17:44:44.542
45. n n NOTIFY_MODULE_END ModuleName="IISCertificateMappingAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
46. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
47. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
48. n n NOTIFY_MODULE_START ModuleName="AnonymousAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
49. n n i AUTH_START AuthTypeSupported="Anonymous" 17:44:44.542
50. n n i AUTH_REQUEST_AUTH_TYPE RequestAuthType="Anonymous" 17:44:44.542
51. n n i AUTH_SUCCEEDED AuthType="3", NTLMUsed="false", RemoteUserName="", AuthUserName="", TokenImpersonationLevel="ImpersonationDelegate" 17:44:44.542
52. n n i AUTH_END 17:44:44.542
53. n n NOTIFY_MODULE_END ModuleName="AnonymousAuthenticationModule", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
54. n n NOTIFY_MODULE_START ModuleName="DefaultAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotification="true", fIsCompletion="false" 17:44:44.542
55. n n NOTIFY_MODULE_END ModuleName="DefaultAuthentication", Notification="AUTHENTICATE_REQUEST", fIsPostNotificationEvent="true", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
56. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
57. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
58. n n NOTIFY_MODULE_START ModuleName="UrlAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
59. n n NOTIFY_MODULE_END ModuleName="UrlAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
60. n n NOTIFY_MODULE_START ModuleName="FileAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
61. n n NOTIFY_MODULE_END ModuleName="FileAuthorization", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
62. n n NOTIFY_MODULE_START ModuleName="UrlAuthorizationModule", Notification="AUTHORIZE_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
63. n n NOTIFY_MODULE_END ModuleName="UrlAuthorizationModule", Notification="AUTHORIZE_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
64. n n NOTIFY_MODULE_START ModuleName="HttpCacheModule", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
65. n n NOTIFY_MODULE_END ModuleName="HttpCacheModule", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
66. n n NOTIFY_MODULE_START ModuleName="OutputCache", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
67. n n NOTIFY_MODULE_END ModuleName="OutputCache", Notification="RESOLVE_REQUEST_CACHE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
68. n n NOTIFY_MODULE_START ModuleName="StaticCompressionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
69. n n NOTIFY_MODULE_END ModuleName="StaticCompressionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
70. n n NOTIFY_MODULE_START ModuleName="HttpRedirectionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
71. n n NOTIFY_MODULE_END ModuleName="HttpRedirectionModule", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
72. n n NOTIFY_MODULE_START ModuleName="ManagedPipelineHandler", Notification="MAP_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
73. n n NOTIFY_MODULE_END ModuleName="ManagedPipelineHandler", Notification="MAP_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
74. n n NOTIFY_MODULE_START ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
75. n n NOTIFY_MODULE_END ModuleName="Session", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
76. n n NOTIFY_MODULE_START ModuleName="Profile", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
77. n n NOTIFY_MODULE_END ModuleName="Profile", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
78. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotification="true", fIsCompletion="false" 17:44:44.542
79. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="REQUEST_ACQUIRE_STATE", fIsPostNotificationEvent="true", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:44.542
80. n n NOTIFY_MODULE_START ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotification="false", fIsCompletion="false" 17:44:44.542
81. n n r MODULE_SET_RESPONSE_ERROR_STATUS
Warning ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The operation completed successfully. (0x0)", ConfigExceptionInfo="" 17:44:45.056
82. n n NOTIFY_MODULE_END ModuleName="ManagedPipelineHandler", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_FINISH_REQUEST" 17:44:45.056
83. n n NOTIFY_MODULE_START ModuleName="AspNetFilterModule", Notification="LOG_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
84. n n NOTIFY_MODULE_END ModuleName="AspNetFilterModule", Notification="LOG_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
85. n n NOTIFY_MODULE_START ModuleName="CustomLoggingModule", Notification="LOG_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
86. n n NOTIFY_MODULE_END ModuleName="CustomLoggingModule", Notification="LOG_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
87. n n NOTIFY_MODULE_START ModuleName="RequestMonitorModule", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
88. n n NOTIFY_MODULE_END ModuleName="RequestMonitorModule", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
89. n n NOTIFY_MODULE_START ModuleName="Session", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
90. n n NOTIFY_MODULE_END ModuleName="Session", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
91. n n NOTIFY_MODULE_START ModuleName="Profile", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
92. n n NOTIFY_MODULE_END ModuleName="Profile", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
93. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="END_REQUEST", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
94. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="END_REQUEST", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
95. n n NOTIFY_MODULE_START ModuleName="ScriptModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
96. n n NOTIFY_MODULE_END ModuleName="ScriptModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
97. n n NOTIFY_MODULE_START ModuleName="DigestAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
98. n n NOTIFY_MODULE_END ModuleName="DigestAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
99. n n NOTIFY_MODULE_START ModuleName="DynamicCompressionModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
100. n n i DYNAMIC_COMPRESSION_START 17:44:45.056
101. n n i DYNAMIC_COMPRESSION_NOT_SUCCESS Reason="NOT_SUCCESS_STATUS" 17:44:45.056
102. n n i DYNAMIC_COMPRESSION_END 17:44:45.056
103. n n NOTIFY_MODULE_END ModuleName="DynamicCompressionModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
104. n n NOTIFY_MODULE_START ModuleName="WindowsAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
105. n n NOTIFY_MODULE_END ModuleName="WindowsAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
106. n n NOTIFY_MODULE_START ModuleName="HttpLoggingModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
107. n n NOTIFY_MODULE_END ModuleName="HttpLoggingModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
108. n n NOTIFY_MODULE_START ModuleName="IsapiModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
109. n n NOTIFY_MODULE_END ModuleName="IsapiModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
110. n n NOTIFY_MODULE_START ModuleName="BasicAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
111. n n NOTIFY_MODULE_END ModuleName="BasicAuthenticationModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
112. n n NOTIFY_MODULE_START ModuleName="IsapiFilterModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
113. n n NOTIFY_MODULE_END ModuleName="IsapiFilterModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
114. n n NOTIFY_MODULE_START ModuleName="ProtocolSupportModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
115. n n NOTIFY_MODULE_END ModuleName="ProtocolSupportModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
116. n n NOTIFY_MODULE_START ModuleName="CustomErrorModule", Notification="SEND_RESPONSE", fIsPostNotification="false", fIsCompletion="false" 17:44:45.056
117. n n NOTIFY_MODULE_END ModuleName="CustomErrorModule", Notification="SEND_RESPONSE", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE" 17:44:45.056
118. n n i HTTPSYS_CACHEABLE HttpsysCacheable="false", Reason="VERB_NOT_GET" 17:44:45.056
119. n n i GENERAL_FLUSH_RESPONSE_START 17:44:45.056
120. n n i GENERAL_FLUSH_RESPONSE_END BytesSent="6141", ErrorCode="The operation completed successfully. (0x0)" 17:44:45.056
121. n n i GENERAL_REQUEST_END BytesSent="6141", BytesReceived="769", HttpStatus="500", HttpSubStatus="0" 17:44:45.056
espresso
Member
80 Points
387 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 06:27 PM|LINK
Ok, finally got a stack trace to work with.
Server Error in '/' Application.
The remote server returned an error: (500) Internal Server Error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
Source Error:
Line 50: requestStream.Close();
Line 51: }
Line 52:
Line 53: response = (HttpWebResponse)request.GetResponse();
Source File: C:\www\xxxxxx\Core\Requestxxx.cs Line: 52
Stack Trace:
[WebException: The remote server returned an error: (500) Internal Server Error.]
System.Net.HttpWebRequest.GetResponse() +5313085
Facebook.Core.Requestxxx.xxxRequest(HttpWebRequest request) in C:\www\xxx\xxx\Core\Requestxxx.cs:52
Facebook.Core.xxxRequest.SendRequest() in C:\www\xxx\xxx\Core\xxxRequest.cs:227
Facebook.Core.xxxRequest.CreateAuthToken() in C:\www\xxx\xxx\Core\xxxRequest.cs:33
Facebook.Core.xxxRequest.GetLoginURL() in C:\www\xxx\xxx\Core\AuthRequest.cs:46
FacebookWeb.FacebookLogin.btnLoginButton_Click(Object sender, EventArgs e) in C:\www\xxx\xxxb\xxx\xxx.aspx.cs:23
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
espresso
Member
80 Points
387 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 08:16 PM|LINK
Entire problem was I needed to use GET. When sending a request out (Whether it's a SOAP message or just a url request to a 3rd party API), you use GET because you want to get the response back. Otherwise POST is used the other way around, if you were the SOA framework and exposed your API, you'd want to take what's coming in (request) and process it....then you'd use POST.
Also, I did not I guess need the following lines:
request.ContentType = "application/x-www-form-urlencoded"; byte[] requestBytes = Encoding.UTF8.GetBytes(request.ToString()); request.ContentLength = requestBytes.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); }Rick Matthys
Contributor
2794 Points
406 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jan 22, 2009 08:33 PM|LINK
Congrads on getting it resolved! As for your GET/POST definitions, it's not quite correct. The difference is that in GET, the name/value pairs are in the URL, where as POST embeds them in the http request. There are reasons to use both in both situations. Anyway, glad you got it fixed.
Disclaimer: Just my opinion. Not my employer or anyone else....
never_again
Member
97 Points
46 Posts
Re: HttpWebRequest.GetResponse() throwing 500 error
Jul 25, 2010 03:15 PM|LINK
I have the same problem.
when I use HttpWebRequest.GetResponse() it throws error 500.
I can also say for sure that the request never reaches an invoked webmethod of the webservice since I perform it localy and debugger never stops in that method.
however adding a webreference and invoking its methods like Serive.Method() works fine.
I'm also 100% sure that XML I post is correct.
Please don't ask why do I use GetResponse if I can just add a reference.. I just have my reasons for that.
the question is why does it works with one webservice and throws 500th error with the other located on the very same machine.
I'm really frustrated.
Please help as soon as possible.
Thank you in advance.
Any help will be greatly appreciated.