好吧,您在这里发布了问题,Can Bilgin给出了答案。我把它贴在这里给那些比你有问题的人。
我认为应该可以手动添加标头...我会尝试使用操作范围...来自较早的示例:
Task<GetADGroupMemberResponse> AccountManagement.GetADGroupMemberAsync(GetADGroupMemberRequest request)
{
// CB: Creating the OperationContext
using (var scope = new OperationContextScope(this.InnerChannel))
{
// CB: Creating and Adding the request header
var header = MessageHeader.CreateHeader("Server", "http://schemas.microsoft.com/2008/1/ActiveDirectory/CustomActions", request.Server);
OperationContext.Current.OutgoingMessageHeaders.Add(header);
return base.Channel.GetADGroupMemberAsync(request);
}
}
由于使用 httpclient 的 http 请求,您可以执行类似的操作(再次来自前面的示例):
var httpClient = new HttpClient();
var httpContent = new HttpRequestMessage(HttpMethod.Post, "http://app.proceso.com.mx/win8/login");
// NOTE: Your server was returning 417 Expectation failed,
// this is set so the request client doesn't expect 100 and continue.
httpContent.Headers.ExpectContinue = false;
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("user", "******"));
values.Add(new KeyValuePair<string, string>("pass", "******"));
httpContent.Content = new FormUrlEncodedContent(values);
HttpResponseMessage response = await httpClient.SendAsync(httpContent);
// here is the hash as string
var result = await response.Content.ReadAsStringAsync();