我如何使用HttpWebResponse / Request [英] How do I use HttpWebResponse/Request

查看:85
本文介绍了我如何使用HttpWebResponse / Request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对要由数据结构标记的地址列表进行地理编码,以判断学生是否属于校园半径10英里的范围。我的问题是我不确定HttpWebResponse正在做什么或如何使用HttpWebResponse。当我运行program.cs文件时,HttpWebResponse会抛出Bad Request 400的异常。我不知道如何解决这个问题。我没有写这段代码。我只是编辑和修改以完成项目。



提前获得帮助。



这是抛出错误的代码。< br $> b $ b

I am trying to geocode a list of addresses to be flagged by a data structure to tell if students are part of a 10 mile radius of the campus or not. My problem is that I am not sure what the HttpWebResponse is doing or how to use the HttpWebResponse. When I run my program.cs file, the HttpWebResponse throws the exception that there is a "Bad Request 400". I am not sure how to fix this issue. I did not write this code. I am just editing and modifying to complete the project.

Thanx in advance for the help.

Here is the code that is throwing the error.

//Submit the HTTP request and check if the job was created successfully.
               using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
               {
                   //
                   // If the job was created successfully, the status code should be
                   // 201 (Created) and the 'Location' header should contain a URL
                   // that defines the location of the new dataflow job. You use this
                   // URL with the Bing Maps Key to query the status of your job.
                   //
                   if (response.StatusCode != HttpStatusCode.Created)
                       throw new Exception("An HTTP error status code was encountered when creating the geocode job.");

                   string dataflowJobLocation = response.GetResponseHeader("Location");
                   if (String.IsNullOrEmpty(dataflowJobLocation))
                       throw new Exception("The 'Location' header is missing from the HTTP response when creating a goecode job.");

                   return dataflowJobLocation;

推荐答案

这篇关于我如何使用HttpWebResponse / Request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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