views:

458

answers:

2

To conect to a third party service I need to make a Https Post. One of the requisites set is to sent a custom content type.

I'm using WebClient, but I can't find how to set it. I've tried making a new class and overriding the CreateRequest Method, but that make request crash.

Is there any way to do that without having to rewrite CopyHeadersTo method?

Thanks in advance

EDIT CopyHeaderTo is a method I've seen using .NET Reflector. It's invoqued from GetWebRequest and sets all Request Headers, including Content-Type, from private properties.

+1  A: 

You could try adding to the Headers collection.

myWebClient.Headers.Add("Content-Type","application/xxx");
Darin Dimitrov
That throws a WebException, saying that Content-Type cannot be changed for current petition.
MaLKaV_eS
Who throws this exception? Is it the server script you are posting to? I have tested the example provided in MSDN and it successfully set the Content-Type header to a custom value.
Darin Dimitrov
A: 

Well, I just missed Request.ContentType propertie. If GetWebRequest method is overried, setting ContentType to whatever value desired does it.

Still, connection to third party is not working. Go figures.

Thanks!

MaLKaV_eS