如何设置Web客户端的Content-Type头? [英] How to set WebClient Content-Type Header?

查看:257
本文介绍了如何设置Web客户端的Content-Type头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要瞬移到第三方服务,我需要做一个HTTPS POST。一组必要条件是要发出的自定义内容类型。



我使用WebClient的,但我找不到如何设置。我试图做一个新的类并覆盖的createRequest方法,但是,让请求崩溃。



有没有办法做到这一点,而无需重写CopyHeadersTo方法<? / p>

在此先感谢



修改 CopyHeaderTo是我见过使用的方法。 NET的反射。这是一个从GetWebRequest invoqued,并将所有请求头,包括内容类型,从私有属性。


解决方案

好吧,我只是错过请求.ContentType propertie。如果GetWebRequest方法overried,设置的ContentType任何值所需做的。



不过,连接到第三方不工作。进入数字。



谢谢!


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.

解决方案

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!

这篇关于如何设置Web客户端的Content-Type头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆