私は、C#で次の設定でhttp投稿を生成するメソッドを取得したいと思います。Http投稿C#with Jsonの応答
POST pqs.php HTTP/1.1
Host: nationalmap.gov/epqs/pqs.php
Content-Type: application/x-www-form-urlencoded
Content-Length: length
x=string&y=string&units=string&output=string
私は例を試みたが、LAT = 36.574832とLONは=ここ-85.411825
は、私が使用していたコードです(彼らがマップに存在しないが、しかし私は、無効な座標を取得しています次のことを試してみました:
public class ElevationUSGISPull
{
public string responseString = null;
private string BASEURL = "http://nationalmap.gov/epqs/pqs.php";
public bool httpPostElevationRequest(string lon,string lat)
{
try
{
using (WebClient client = new WebClient())
{
byte[] response =
client.UploadValues(BASEURL, new NameValueCollection()
{
{ "x", lon },
{ "y", lat },
{"units", "feet" },
{"output","json" },
});
string result = System.Text.Encoding.UTF8.GetString(response);
responseString = result;
}
return true;
}
catch(Exception eX)
{
return false;
}
}
}
私は取得していますエラーは以下の通りです:
はまたいずれかを持っています1人は.govウェブサイトで標高データを取得しようとしました。私はGoogleのサーバーを使用していますが、リクエストの数に関連する多くの制限があり、特定のエリアに対して多くのリクエストを実行しようとしています。
以下は、良いjsonレスポンスで緯度と経度を確認するためのウェブサイトです。すべて
感謝。
また、私はここに、次の例を試してみました:
をしかし、私は次のエラーを与えています。私はこれまでのコード修正Exception thrown: 'System.NullReferenceException'
:
public async Task<string> HTTPPOST(string lon, string lat)
{
var client = new HttpClient();
client.BaseAddress = new Uri(BASEURL);
var request = new HttpRequestMessage(HttpMethod.Post, "");
var keyValues = new List<KeyValuePair<string, string>>();
keyValues.Add(new KeyValuePair<string, string>("x", lon));
keyValues.Add(new KeyValuePair<string, string>("y", lat));
keyValues.Add(new KeyValuePair<string, string>("units", "feet"));
keyValues.Add(new KeyValuePair<string, string>("output", "json"));
request.Content = new FormUrlEncodedContent(keyValues);
var response = await client.SendAsync(request);
return response.ToString();
}
他の座標を試しましたか? –
同じ結果...ウェブサイトのGUIが標高データを持つ良いjson応答を返します。 :/ – nader
@ MarkC.is私は生成しているhttp投稿をコンソールに出力する方法があります。 – nader