简体   繁体   English

如何在 WCF web 服务 ZD7EFA19FBE7D3972FD5ADB602422 中请求之前创建自定义 header

[英]How to create custom header before request in WCF web service C#

I want to integrate bluesuit ( https://docs.bluesuit.com/?shell#send-document ) in C#.我想在 C# 中集成 bluesuit ( https://docs.bluesuit.com/?shell#send-document )。 I want to upload a .pdf to bluesuit by setting Content-Type and Authorization Bearer using a WCF service.我想通过使用 WCF 服务设置Content-TypeAuthorization Bearer将 .pdf 上传到.pdf How to add this in header and call https://docs.bluesuit.com/?shell#send-document post method and get response and integrate bluesuit in C# with WCF? How to add this in header and call https://docs.bluesuit.com/?shell#send-document post method and get response and integrate bluesuit in C# with WCF?

Simply I just want to call a third party (bluesuit) post url in wcf service and get response from this third party (bluesuit) post url so how to call this third party post url in a WCF method? Simply I just want to call a third party (bluesuit) post url in wcf service and get response from this third party (bluesuit) post url so how to call this third party post url in a WCF method?

Thanks in advance.提前致谢。 need help please advice.需要帮助请指教。

You can do it like this:你可以这样做:

// Code to get a static WebClient
private static WebClient GetWebClient
{
    get
    {
        var client = new WebClient
        {
            BaseAddress = "https://docs.bluesuit.com/?shell#send-document",
            UseDefaultCredentials = true
        };
        client.QueryString.Clear();
        client.Headers.Clear();
        client.Headers.Add("content-type", "application/pdf");
        return client;
    }
}

Usage inside your function where you need to get response from bluesuit: function 中的用法,您需要从 bluesuit 获得响应:

var client = GetWebClient;
// getToken() call returns you the Token as a string
client.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + getToken());
var data = "Your data goes here";
var response = client.UploadString(url, "POST", data);

Process the response as per your use case.根据您的用例处理响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM