C# 如何在C语言中使用restfullweb服务发送数据#

C# 如何在C语言中使用restfullweb服务发送数据#,c#,sql-server,web-services,rest,windows-phone-8,C#,Sql Server,Web Services,Rest,Windows Phone 8,我正在开发一个Windows Phone 8.1应用程序。 我是C#和WP的新手。我使用restfull web服务进行sql server连接,但无法将数据发送到服务器。我收到一条错误消息“请求错误” 这是我的登录页面代码bihend KullaniciManager km = new KullaniciManager(); km.Login(); HttpClient httpClient = new System.Net.Http.HttpC

我正在开发一个Windows Phone 8.1应用程序。 我是C#和WP的新手。我使用restfull web服务进行sql server连接,但无法将数据发送到服务器。我收到一条错误消息“请求错误”

这是我的登录页面代码bihend

KullaniciManager km = new KullaniciManager();
            km.Login();
            HttpClient httpClient = new System.Net.Http.HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:3577/KullaniciService.svc/Login");
            HttpResponseMessage response = await httpClient.SendAsync(request);

            MessageDialog msgbox = new MessageDialog("Serverdan gelecek hata mesajı");
            await msgbox.ShowAsync();
我的BLL代码在这里

 public LoginResponse KullaniciKontrolEt(string kulAdi, string sifre)
    {
        LoginResponse response = null;
        using (NeydiolilacEntities noi = new NeydiolilacEntities())
        {
            object data = noi.ta_Kullanici.Where(x => x.Kul_Ad == kulAdi && x.Kul_Sifre == sifre && x.Kul_Statu == true).SingleOrDefault();

            response = new LoginResponse()
            {
                Data = data
            };

            return response;
        }
谢谢你的帮助:)

*

注意:Win8.1的代码

public async Task<string> GeneralRequestHandler(string RequestUrl, object ReqObj)
        {
            try
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(ReqObj);
                HttpContent content = new StringContent(json);
                Windows.Web.Http.IHttpContent c = new Windows.Web.Http.HttpStringContent(json);
                c.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/json");
                Windows.Web.Http.Filters.HttpBaseProtocolFilter aHBPF = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();

                aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
                aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidName);
                string responseText;
                using (var handler = new Windows.Web.Http.HttpClient(aHBPF))
                {
                    Windows.Web.Http.HttpResponseMessage r = await handler.PostAsync(new Uri(RequestUrl), c);
                    responseText = await r.Content.ReadAsStringAsync();
                }
            }
            catch (HttpRequestException ex)
            {

            }

            return responseText;
        }
公共异步任务GeneralRequestHandler(字符串RequestUrl,对象ReqObj)
{
尝试
{
字符串json=Newtonsoft.json.JsonConvert.SerializeObject(ReqObj);
HttpContent=新的StringContent(json);
Windows.Web.Http.IHttpContent c=新的Windows.Web.Http.HttpStringContent(json);
c、 Headers.ContentType=new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue(“应用程序/json”);
Windows.Web.Http.Filters.HttpBaseProtocolFilter aHBPF=新的Windows.Web.Http.Filters.HttpBaseProtocolFilter();
aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidName);
字符串响应文本;
使用(var handler=newwindows.Web.Http.HttpClient(aHBPF))
{
Windows.Web.Http.HttpResponseMessage r=wait handler.PostAsync(新Uri(RequestUrl),c);
responseText=wait r.Content.ReadAsStringAsync();
}
}
捕获(HttpRequestException-ex)
{
}
返回响应文本;
}
*

public async Task<string> GeneralRequestHandler(string RequestUrl, object ReqObj)
        {
            try
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(ReqObj);
                HttpContent content = new StringContent(json);
                Windows.Web.Http.IHttpContent c = new Windows.Web.Http.HttpStringContent(json);
                c.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/json");
                Windows.Web.Http.Filters.HttpBaseProtocolFilter aHBPF = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();

                aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.Untrusted);
                aHBPF.IgnorableServerCertificateErrors.Add(Windows.Security.Cryptography.Certificates.ChainValidationResult.InvalidName);
                string responseText;
                using (var handler = new Windows.Web.Http.HttpClient(aHBPF))
                {
                    Windows.Web.Http.HttpResponseMessage r = await handler.PostAsync(new Uri(RequestUrl), c);
                    responseText = await r.Content.ReadAsStringAsync();
                }
            }
            catch (HttpRequestException ex)
            {

            }

            return responseText;
        }