问题
As the title says, i need to set this flag to false for my app, like so:
ServicePoint.Expect100Continue = false;
However neither ServicePoint nor ServicePointManager are accessible, and i can't find another way to set this property. Also, there is no app.config so setting it via configuration is also not possible.
If i do no set this to false, the flag is sent in the request and a CommunicationException occurs.
I cannot change server code, i am only a consumer of server data.
The service is added with the "Add Service Reference" dialog. Any method call results in:
The underlying connection was closed: An unexpected error occurred on a receive.
When i call the same service, added with "Add Service Reference" from a console application, there is the same error. The reason is the Expect100Continue Attribute. If i remove it using the usual methods, it works in the console app.
So, i'd like to know what the equivalent is for Windows Store apps.
回答1:
I ended up taking the auto-generated classes from "add service reference" and serializing them myself. I then use HttpClient to make my calls. It is possible to set the ExpectContinue flag there like this:
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.ExpectContinue = false;
....code!
}
来源:https://stackoverflow.com/questions/12799196/servicepoint-expect100continue-for-windows-store-apps