Intermittent Server cannot set status after HTTP headers have been sent - asp.net-web-api

I am getting an intermittent error in the event logs "Server cannot set status after HTTP headers have been sent". The webapi site is working fine and delivering the correct output even when this happens.
Exception information:
Exception type: HttpException
Exception message: Server cannot set status after HTTP headers have been sent. at System.Web.HttpResponse.set_StatusCode(Int32
value) at System.Web.HttpResponseWrapper.set_StatusCode(Int32
value) at
System.Web.Http.WebHost.HttpControllerHandler.d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Web.Http.WebHost.HttpControllerHandler.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Web.Http.WebHost.HttpControllerHandler.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown --- at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) at
System.Web.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult
result) at
System.Web.HttpApplication.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult
ar) at
System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult
ar)
The response object is manipulated directly (the format of the json is not known until runtime) as follows.
var response= HttpContext.Current.Response;
response.StatusCode = (int) HttpStatusCode.OK;
response.Headers.Add("X-Robots-Tag", "noindex, nofollow");
response.Write("Some json");
response.Flush();
response.End();
response.End is required, I do not understand why, a similar error occurs if this line is missed out.
Why does this happen, and is there a better way of doing it?

Since you tagged your question with asp.net-web-api I assume that you are using that code in an api controller method. If so, I suggest returning the unknown Json like this:
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("Some json", System.Text.Encoding.UTF8, "application/json")
};
response.Headers.Add("X-Robots-Tag", "noindex, nofollow");
return response;
Above code was taken from the following links and adapted:
Put content in HttpResponseMessage object
and
Add a custom response header in ApiController (questions and answers on SO)

Related

Dynamics 365 WebApi - BATCH request - Error - The message header ' ' is invalid

Anyone is facing the follow error message, trying to execute a BATCH request for Dynamics 365 WebApi? I'm using Postman.
{
"Message": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionMessage": "The message header ' ' is invalid. The header value must be of the format '<header name>: <header value>'.",
"ExceptionType": "Microsoft.OData.ODataException",
"StackTrace": " at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ValidateHeaderLine(String headerLine, String& headerName, String& headerValue)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ReadHeaders()\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReaderStream.ProcessPartHeader(String& contentId)\r\n at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchReader.SkipToNextPartAndReadHeaders()\r\n at Microsoft.OData.ODataBatchReader.ReadImplementation()\r\n at Microsoft.OData.ODataBatchReader.InterceptException[T](Func`1 action)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsyncImplementationAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<>c__DisplayClass9_0.<<ParseBatchRequestsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.<ExecuteAsync>d__11`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.<ExecuteAsync>d__6`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataBatchHandler.<ParseBatchRequestsAsync>d__9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.OData.Batch.DefaultODataBatchHandler.<ProcessBatchAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Batch.HttpBatchHandler.<SendAsync>d__0.MoveNext()",
"ErrorCode": "0x0"
}
Image of Postman headers
Here's my Body Content:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task#odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task#odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
Nothing looks wrong except the extra white lines between Batch request unique identifier & headers, the error maybe coming because of that. Remove the extra white lines like below:
--batch_AAA123
Content-Type: multipart/mixed;boundary=changeset_BBB456
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 1
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 1 in batch","regardingobjectid_account_task#odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456
Content-Type: application/http
Content-Transfer-Encoding:binary
Content-ID: 2
POST https://copasa.crm2.dynamics.com/api/data/v9.1/tasks HTTP/1.1
Content-Type: application/json;type=entry
Accept: application/json
{"subject":"Task 2 in batch","regardingobjectid_account_task#odata.bind":"https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)"}
--changeset_BBB456--
--batch_AAA123
Content-Type: application/http
Content-Transfer-Encoding:binary
GET https://copasa.crm2.dynamics.com/api/data/v9.1/accounts(1AD045E1-7DE4-E911-A812-000D3AC058C3)/Account_Tasks?$select=subject HTTP/1.1
Accept: application/json
--batch_AAA123--
I had the same problem only it was saying that the message header '\t' was invalid. On one of my blank lines I had tab character that I couldn't see. Once I found it and removed it, my request went through just fine.

HttpMessageNotReadableException: Required request body is missing (Occasional) - SpringMVC Default Controller Request Mapping HTTP Method?

I have the following code which represents an Ajax POST request:
#RequestMapping("/participant/insertEvent")
public boolean insertEvent(Principal principal, #RequestBody String json, HttpServletRequest request) throws Exception {
//...
//return true or false
}
JS:
$.ajax({
type : "post",
dataType : "json",
url : '/app/participant/insertEvent',
data : JSON.stringify({'p1': p1, 'p2' : p2})
});
The app is deployed in Production and everything has been working with many users the whole week.
This morning I got the following production issue at this method (insertEvent):
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean
app.controller.participant.AjaxOperationsController.insertEvent(java.security.Principal,java.lang.String,javax.servlet.http.HttpServletRequest) throws java.lang.Exception at
org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:161) at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124) at
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) at ...
I'm wondering, is it because I didn't explicitly specify this is a method={RequestMethod.POST} ?
But if I don't specify an HTTP method, what is the default?
However, if this is the issue, then why does the app work 99% of the time, and not for that one user?
FYI, the error was caused by including in the JSON an un-encoded % (percent) special char coming from a TextArea value.

difference between two http requests

I have two http requests, one written in curl, one written in javascript in chrome. The curl request works but the chrome request doesn't, but i'm not sure why.
Chrome:
PUT /api/Account HTTP/1.1
Host: mydomain.co.nz
Connection: keep-alive
Content-Length: 152
Pragma: no-cache
Cache-Control: no-cache
Authorization: Bearer eyJhb..
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Content-Type: multipart/form-data; boundary=--------------------------33e4cd665cd7a003
Accept: application/json
Referer: http://localhost:4200/conversations
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
--------------------------33e4cd665cd7a003
Content-Disposition: form-data; name="data"
{"isoncall" : true}
--------------------------33e4cd665cd7a003--
curl:
PUT /api/Account HTTP/1.1
Host: mydomain.co.nz
User-Agent: curl/7.51.0
accept: application/json
authorization: Bearer eyJhbGciO....
cache-control: no-cache
Content-Length: 158
Expect: 100-continue
Content-Type: multipart/form-data; boundary=--------------------
----a8c24af99c272f79
--------------------------a8c24af99c272f79
Content-Disposition: form-data; name="data"
{"isoncall" : true}
--------------------------a8c24af99c272f79--
The error i'm getting with chrome is:
[{"error":"Unexpected end of Stream, the content may have already been read by another component. ","type":"IOException","stack":" at Microsoft.AspNetCore.WebUtilities.MultipartReaderStream.d__41.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.WebUtilities.MultipartReader.d__20.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Http.Features.FormFeature.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Mvc.ModelBinding.FormValueProviderFactory.d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Mvc.ModelBinding.CompositeValueProvider.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Mvc.Internal.DefaultControllerArgumentBinder.d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__22.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__20.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at IdentityModel.AspNetCore.ScopeValidation.ScopeValidationMiddleware.d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware1.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationMiddleware.d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at Celo.Api.Middleware.Exceptions.ExceptionHandlingMiddleware.d__5.MoveNext() in D:\a\1\s\src\Celo.Api\Middleware\Exceptions\ExceptionHandlingMiddleware.cs:line 41"}]
I'm not sure how this is failing.
for reference the curl command is:
curl -X PUT https://mydomain.co.nz/api/Account -H 'accept: application/json' -H 'authorization: Bearer eyJhb..' -H 'cache-control: no-cache' -F 'data={"isoncall" : true}'
and the javascript call is:
let xhr:XMLHttpRequest = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log('200', xhr.response)
//resolve(<MyEntity>JSON.parse(xhr.response));
} else {
console.log('err', xhr.response)
//reject(xhr.response);
}
}
};
xhr.open('PUT', 'https://mydomain.co.nz/api/Account', true);
xhr.setRequestHeader("Accept", "application/json")
xhr.setRequestHeader("Authorization", this.authService.getAuth())
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=--------------------------33e4cd665cd7a003')
xhr.send(`--------------------------33e4cd665cd7a003
Content-Disposition: form-data; name="data"
{"isoncall" : true}
--------------------------33e4cd665cd7a003--`)
A clear difference between the two requests is that in your XHR request, you don't prefix the boundary in the body of the request with two dashes as required.
If you look at the request generated by CURL, you will see that the two boundaries have two additional dashes prefixed (when compared to the boundary in the header), as well as two extra dashes suffixed to the last boundary of the body. You don't have the prefixes in your javascript code.
Now, having said that, I can suggest two possible solutions:
Fix your current code - this is possibly a quick fix.
As mentioned above, you need to add the additional -- prefix to the boundary in the body.
Secondly, I would avoid multiline strings the way you have them and use \n as line separator.
This would result in the following javascript:
xhr.open('PUT', 'https://mydomain.co.nz/api/Account', true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", this.authService.getAuth());
xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=--------------------------33e4cd665cd7a003')
xhr.send(`----------------------------33e4cd665cd7a003\n' +
'Content-Disposition: form-data; name="data"\n\n' +
'{"isoncall" : true}\n\n' +
'----------------------------33e4cd665cd7a003--');
You could also switch to the XHR FormData API and avoid dealing with all this manually.
var formData = new FormData();
formData.append("data", '{"isoncall" : true}');
xhr.open('PUT', 'https://mydomain.co.nz/api/Account', true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Authorization", this.authService.getAuth());
xhr.send(formData);

No headers available in xhr object when an UNAUTHORIZED error occurs - IE10

I have a CORS Ajax call to a web api. I have a message handler which throws an:
var msg = new HttpResponseMessage(HttpStatusCode.Unauthorized) { ReasonPhrase = "Oops!!!" };
throw new HttpResponseException(msg);
On the client I can't get no response headers, tried:
error: function (xhr, error) {
var result = xhr.getResponseHeader("Response");
but result is null and no other heades are available.
The Debugger shows correctly a 401!
Should I return the Unauthorized Exception differently from the server?
Update:
I forgot the add the Origin header to my HttpResponseException, in order to get the headers.
But in IE10 I don't get any headers, only error message
"error"
How can I know what happend, when using IE10?
Here is related question.
As I cannot get the Headers when returning a 401 response.
No instead I return NoContent StatusCode, which triggers the AJAX success eventhandler.
Now I have to check the response header "response" (which I manually add on the server side) in the success eventhandler, in order to make it work in IE 10:
Server:
var msg = new HttpResponseMessage(HttpStatusCode.NoContent) { ReasonPhrase = "UNAUTHORIZED" };
msg.Headers.Add("RESPONSE", "401");
AddCORSHeaders(msg.Headers, request);
return await Task.FromResult(msg);
Client:
error: function (jqXhr, error) {
var isAuth= jqXhr.getResponseHeader("Response");
Now I get a "response" header with value 401.
IF SOMEONE HAS A BETTER APPROACH, I'LL EXCEPT THE ANSWER !
In IE10 the ajax error eventhandler you get readyState=0 and status="".
In Chrome you get a 401 and readyState=4.

WebRequest time out error

I tried to build an application in Mono using the setting "Mono 2.10.2", but the the following errors.
Unhandled Exception: System.Net.WebException: The request timed out
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00046] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\System\System.Net\HttpWebRequest.cs:813
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\System\System.Net\HttpWebRequest.cs:825
The bit of code causing this issue is:
string url = "http://webFarm/config.prop";
WebRequest req = WebRequest.Create(url);
WebResponse resp = req.GetResponse();
It failed immediately. But if I switch the setting to "Default Runtime" instead of "Mono 2.10.2", everything is OK. Could anyone help me with this?
Regards,
David
I'm also getting this error using the code:
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create("https://api-3t.sandbox.paypal.com/nvp");
objRequest.Timeout =15000;
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
using (StreamWriter myWriter = new
StreamWriter(objRequest.GetRequestStream()))
myWriter.Write(strPost);
causes exception at GetRequestStream() :
System.Net.WebException: The request timed out
at System.Net.HttpWebRequest.GetRequestStream () [0x0005f] in
/usr/src/redhat/BUILD/mono-2.10.2/mcs/class/System/System.Net/HttpWebRequest.cs:752
at NVPAPICaller.HttpCall (System.String NvpRequest) [0x00000] in <filename
unknown>:0
--------------------------------------------------------------------------------
Version information: Mono Runtime Version: 2.10.2 (tarball Mon Apr 18
18:57:39 UTC 2011); ASP.NET Version: 2.0.50727.1433
You should revert back to older Mono 2.10 , 2.10.1 will probably work.

Resources