httpclient postasync windows phone 8.1通用app第二次调用404错误 [英] httpclient postasync windows phone 8.1 universal app second call 404 error

查看:316
本文介绍了httpclient postasync windows phone 8.1通用app第二次调用404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通用Windows Phone 8.1应用程序中遇到httpclient问题。
我一直在寻找,但我在任何帖子中都没有有效的解决方案。

I have a problem with httpclient in a universal windows phone 8.1 app. I've been looking but i have not a valid solution in any post.

问题是,当我第一次调用Web服务时正确,但当我调用它,第二次或第三次,给我一个错误404.

the problem is that, when i call to the web service first time runs correctly, but when i call it, second or third time, gives me an error 404.

直到你重新启动应用程序将不会再次运行。

Until you restart the application will not run again.

我需要在post函数中发送该数据,因为我想发送一个xml格式化为字符串。

i need to send that data in a post function cause i want to send a xml formated to string.

我的代码非常简单:

var handler = new HttpClientHandler
        {
            Credentials = new
                NetworkCredential("user", "pass", "domain")
        };


        using (var client = new HttpClient(handler))
        {
            var formContent = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("XMLText", XMLText),
                        new KeyValuePair<string, string>("param1", "textParam1")
                    });

            HttpResponseMessage response = new HttpResponseMessage();
            response = await client.PostAsync(URL, formContent);
            var responseString = response.Content.ReadAsStringAsync().Result;
            MessageDialog msgbox = new MessageDialog(responseString);
            await msgbox.ShowAsync();
        }

我的网络服务更简单:

[WebMethod]
    public String SetEnvioXML(string XMLText, string param1)
    {
        return XMLText;
    }

任何解决方案?

对不起我的英文和所有人!

Sorry for my english and thaks for all!

欢迎任何帮助!

推荐答案

最后我找到了解决方案,我将身份验证从Windows身份验证更改为IIS中的基本身份验证,并在其中设置域。然后我尝试:

Finally i found the solution, i changed the autentication from windows autentication, to basic autentication in IIS, setting the domain in it. Then i try that:

client = new HttpClient();

var authHeader = new AuthenticationHeaderValue(Basic,Convert.ToBase64String(Encoding。 UTF8.GetBytes(string.Format({0}:{1},usuario,contraseña))));
client.DefaultRequestHeaders.Authorization = authHeader;

client = new HttpClient();
var authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", "usuario", "contraseña")))); client.DefaultRequestHeaders.Authorization = authHeader;

并且它规则。谢谢你的所有答案!

And it rules. Thanks for all of your answers!

这篇关于httpclient postasync windows phone 8.1通用app第二次调用404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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