请求URI太大

时间:2012-10-17 08:09:58

标签: c# .net google-fusion-tables google-api-client

我使用了OAuth2授权http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2的示例,但我使用的是Fusion Tables Service,而不是Tasks Service。

问题是当我尝试在表中插入新行时出现错误414 - 请求URI太大。

const string Geometry = "<Polygon>" + "<outerBoundaryIs>" + "<LinearRing>" + "<coordinates>" +
"-86.8331071413617,33.9491997229225 -86.8207076186559,33.9412000308542 -86.8207076186559,33.9575993995941 -86.7907087734001,33.9531995689566 -86.7919087272103,33.9631991840419 -86.7627098511612,33.9755987067476 -86.7611099127476,33.9955979369182 -86.7415106671804,33.9991977983489 -86.7203114831996,34.0323965204321 -86.707111991287,34.0299966128117 -86.7043120990631,34.0579955350505 -86.6843128688925,34.0543956736198 -86.7047120836665,34.0803946728416 -86.6923125609607,34.0923942109439 -86.6867127765129,34.0795947036348 -86.6687134693594,34.0835945496689 -86.6527140852229,34.107993610477 -86.622715239967,34.1227930408032 -86.6131156094851,34.1135933949248 -86.5995161329691,34.1199931485794 -86.5903164870907,34.1463921324046 -86.5455182115085,34.1855906235389 -86.5555178265938,34.1887905003662 -86.5543178727836,34.2051898691061 -86.5399184270608,34.2255890838801 -86.5235190583209,34.2263890530869 -86.5195192122867,34.2519880677053 -86.4531217681204,34.2591877905667 -86.3035275264443,34.0991939492019 -86.3323264178899,34.0463959815516 -86.3335263717002,33.9819984604022 -86.3703249552141,33.9396000924406 -86.3255266796319,33.940000077044 -86.3487257866298,33.9100012317881 -86.3423260329752,33.8868021247902 -86.4083234925382,33.8340041571398 -86.4303226457259,33.819604711417 -86.4451220760521,33.8260044650716 -86.5219191199072,33.8020053888668 -86.5775169797815,33.8020053888668 -86.5743171029542,33.7652068053529 -86.647914269982,33.7660067745598 -86.7591099897305,33.8408038953978 -86.883905185995,33.8432038030183 -86.9535025069887,33.8152048807794 -86.963502122074,33.8584032179479 -86.9623021682638,33.8676028638264 -86.947902722541,33.8616030947752 -86.9519025685751,33.8716027098605 -86.9203037849055,33.8728026636708 -86.9275035077669,33.8984016782891 -86.9167039234748,33.9156010162358 -86.8867050782189,33.9168009700461 -86.8859051090121,33.9340003079928 -86.8595061251869,33.9292004927519 -86.8331071413617,33.9491997229225" +
"</coordinates>" + "</LinearRing>" + "</outerBoundaryIs>" + "</Polygon>";

var sqlValue = string.Format(
"INSERT INTO {0} (Hash, Geometry, Timestamp) VALUES ('3eb906069dd01a74352a2b1f9e5cec3f', '{1}', '{2}')", 
TableId, Geometry, DateTime.Now);

var sqlresponse = service.Query.Sql(sqlValue).Fetch();

似乎使用了GET请求而不是POST。 有人可以告诉我我的代码有什么问题,或者是否可以插入大量数据?

更新

官方FusionTables API参考告诉我们不应该提供“sql”api方法的请求体。如果我们尝试使用https://developers.google.com/apis-explorer/#p/fusiontables/v1/fusiontables.query.sql来测试我们的INSERT请求和下一个sql:

INSERT INTO 1Fyxt7bxFiCaT5jnUHdzv8xoCA6C8ERysS-aXELg (Hash, Geometry, Timestamp) VALUES ('3eb906069dd01a74352a2b1f9e5cec3f', '<Polygon><outerBoundaryIs><LinearRing><coordinates>-86.8331071413617,33.9491997229225 -86.8207076186559,33.9412000308542 -86.8207076186559,33.9575993995941 -86.7907087734001,33.9531995689566 -86.7919087272103,33.9631991840419 -86.7627098511612,33.9755987067476 -86.7611099127476,33.9955979369182 -86.7415106671804,33.9991977983489 -86.7203114831996,34.0323965204321 -86.707111991287,34.0299966128117 -86.7043120990631,34.0579955350505 -86.6843128688925,34.0543956736198 -86.7047120836665,34.0803946728416 -86.6923125609607,34.0923942109439 -86.6867127765129,34.0795947036348 -86.6687134693594,34.0835945496689 -86.6527140852229,34.107993610477 -86.622715239967,34.1227930408032 -86.6131156094851,34.1135933949248 -86.5995161329691,34.1199931485794 -86.5903164870907,34.1463921324046 -86.5455182115085,34.1855906235389 -86.5555178265938,34.1887905003662 -86.5543178727836,34.2051898691061 -86.5399184270608,34.2255890838801 -86.5235190583209,34.2263890530869 -86.5195192122867,34.2519880677053 -86.4531217681204,34.2591877905667 -86.3035275264443,34.0991939492019 -86.3323264178899,34.0463959815516 -86.3335263717002,33.9819984604022 -86.3703249552141,33.9396000924406 -86.3255266796319,33.940000077044 -86.3487257866298,33.9100012317881 -86.3423260329752,33.8868021247902 -86.4083234925382,33.8340041571398 -86.4303226457259,33.819604711417 -86.4451220760521,33.8260044650716 -86.5219191199072,33.8020053888668 -86.5775169797815,33.8020053888668 -86.5743171029542,33.7652068053529 -86.647914269982,33.7660067745598 -86.7591099897305,33.8408038953978 -86.883905185995,33.8432038030183 -86.9535025069887,33.8152048807794 -86.963502122074,33.8584032179479 -86.9623021682638,33.8676028638264 -86.947902722541,33.8616030947752 -86.9519025685751,33.8716027098605 -86.9203037849055,33.8728026636708 -86.9275035077669,33.8984016782891 -86.9167039234748,33.9156010162358 -86.8867050782189,33.9168009700461 -86.8859051090121,33.9340003079928 -86.8595061251869,33.9292004927519 -86.8331071413617,33.9491997229225</coordinates></LinearRing></outerBoundaryIs></Polygon>', '10/17/2012 1:35:07 PM')

然后将使用POST请求,但无论如何都将包含INSERT语句以查询字符串。

所以,我的问题仍然是相同的:是否可以使用FusionTables API .NET Client插入大量数据?

1 个答案:

答案 0 :(得分:0)

问题是您通过GET方法连接到服务器并且查询字符串太长。您必须使用POST来解决此问题。通常的做法是,在插入/更新/删除时使用POST,在查询数据时使用GET

您可以详细了解HTTP Error 414 Request URI too longGET vs POST