5

I am creating a clone of the facebook Rest API in c#, I am testing it with the facebook PHP sdk. The problem I am having is that the responses sent by my net Rest Service contain utf-8 Bom in front of it and Facebook SDK is not able to parse the responses correctly. Any ideas on how to resolve this problem.

3 Answers 3

4

If you can specify a specific Encoding to your service, then you can use new UTF8Encoding(false) which is UTF-8 without BOM.

Sign up to request clarification or add additional context in comments.

Comments

2

I don't know what you are returning in your service, but if it is a string like mine (I was returning a json), you can simply return a Message object instead with the string in it (from System.ServiceModel.Channels - google it) and then at the end of your service method implementation just do this:

Encoding utf8 = new System.Text.UTF8Encoding(false); //false == no BOM return WebOperationContext.Current.CreateTextResponse(stringWithContent, "application/json;charset=utf-8", utf8); 

Comments

-1

The Wikipedia UTF-8 article suggests that the pretend-BOM that Windows applications frequently prepend to the actual content is three bytes long. Can you simply not send the first three bytes of your generated content?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.