We are experiencing problems with calling a Web Service that runs on Oracle HTTP Server powered by Apache.
The Web Service returns 400 Bad Request.
The explanation I got from the developer of the Web Service is that Apache doesn't accept messages that contains the information "charset=utf-8" in the Content-Type field in the HTTP Header.
How can I remove the charset=utf-8 from the Content-Type field
I have tried to override the GetWebRequest method for my call to the Web Service without any success.
Any ideas
Thanks,
Simon

How to remove "charset=UTF-8" from Content-Type
Dennis Kriek
Right, overriding GetWebRequest() does not work, because the sequence of the client processing is:
1. GetWebReqiest< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
2. Do BeforeSerialize processing
3. Serialize parameters.
The request.ContentType is set on stage 2, so you need to alter the request between #2 and #3.
You have a couple of options:
1. If Apache prefer a different charset, you could change it by setting the RequestEncoding on your client proxy.
2. If you do not want the attribute in the ContentType at all, it is a bit more difficult and requires Whidbey: you would need to override the GetWebRequest(), and keep it in your client instance, you also need to override the GetWriterForMessage() (this is new in Whidbey), and when your GetWriterForMessage() is called, you can alter the cached request.ContentType, just make sure that if you use ContentType = "text/xml;", your client.RequestEncoding is Encoding.UTF8 or null (if RequestEncoding and charset in ContentType mismatched, you will get "The request failed with HTTP status 400: Bad Request")
Sample (not thread safe) client:
using System.Text;
using System.Net;
using System.Xml;
public class Service : System.Web.Services.Protocols.SoapHttpClientProtocol {
WebRequest currentRequest;
protected override WebRequest GetWebRequest(Uri uri)
{
currentRequest = base.GetWebRequest(uri);
return currentRequest;
}
protected override XmlWriter GetWriterForMessage(SoapClientMessage message, int bufferSize)
{
currentRequest.ContentType = "text/xml;";
message.ContentType = "text/xml;";
return base.GetWriterForMessage(message, bufferSize);
}
}
dbae
Hello,
I'm trying to create a simple aspx page that returns a valid JSON Response and I'm having the same problem, I've tried to override the ProcessRequest too but it doesn't work.
All I need is to return a simply "application/jsonrequest" instead of "application/jsonrequest; charset=utf-8".
Any ideas
Thanks in advance.
Scott Taylor
FYI, found a workaround for the struts/FormFile issue.
The issue(s)
a) Struts doesn't resolve the file when there is Charset information in the Content-Type header for a multipart/form-data post.
b) Winhhtp on Vista (dll version 6) adds '; Charset=UTF-8' to the Content-Type
The fix;
Add the text '; Charset=UTF-8' to the boundary
Example in VB6
'Construct the Multipart Message to Send
msg = ""
msg = msg & "--" & bndry & "; Charset=UTF-8" & vbCrLf
msg = msg & "Content-Disposition: form-data; name=""xmlFile""; filename=""select.xml""" & vbCrLf
msg = msg & "Content-Type: text/xml" & vbCrLf & vbCrLf
msg = msg & xmlDocument.xml & vbCrLf
msg = msg & "--" & bndry & "; Charset=UTF-8" & "--" & vbCrLf
....
xmlhttp.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & bndry & "; Charset=UTF-8"
...
Daniel Herling Microsoft
Hi Elena,
Got the same problem submiiting a file from VisualBasic 6 using winhttp to a JSP server.
I'm setting the header in VB withouth the charset;
xmlhttp.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & boundary
but recieve it on the server site with a charset !
multipart/form-data; boundary=---------------------------306f991c2cf1832a; Charset=UTF-8
It is only doing this on the Vista machine, when I check the verrsion of winhttp.dll is see version 6 (although I can't find any info about winhttp 6)
What can I do on the VB client side to stop the Charset from being added.
Kind Regards
Meindert