POST method returns a 414 - Request uri too long error when passing complex geometry.

20492
10
Jump to solution
06-18-2013 06:25 AM
BobCarberry
New Contributor
I am trying to perform a query operation on a layer in a mapservice by passing in a geometry of type polygon.  The passed in geometry is used to intersect the layer and return the records that the geometry intersected. This works fine for simple geometry however, when I try passing in a complex geometry (one with many vertices, like a curve), I get an error 414 - Request too long.  I am performing this function in a .NET webservice using the POST method for an HttpWebRequest.  What's interesting is if I use the interface on server and copy/paste the geometry string, and clicking POST, it works fine.  Any ideas?
0 Kudos
1 Solution

Accepted Solutions
RichardWatson
Frequent Contributor
Put the arguments in body and not the URI.

View solution in original post

0 Kudos
10 Replies
RichardWatson
Frequent Contributor
Put the arguments in body and not the URI.
0 Kudos
BobCarberry
New Contributor
Thanks for your reply, Richard however I believe I am writing to the body, here is my code:

    Private Shared Function PostIt(ByVal baseUrl As String, ByVal input As String) As String
        Dim responseString As String
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader

        Dim byteData() As Byte
        Dim postStream As Stream = Nothing

        request = DirectCast(WebRequest.Create(baseUrl + input), HttpWebRequest)
        ' Set type to POST 
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        ' Create a byte array of the data we want to send 
        byteData = UTF8Encoding.UTF8.GetBytes(input)
        ' Set the content length in the request headers 
        request.ContentLength = byteData.Length

        Try

            postStream = request.GetRequestStream()
            postStream.Write(byteData, 0, byteData.Length)
        Finally

            If Not postStream Is Nothing Then postStream.Close()
        End Try

    
        Try

            ' Get response 
          '(CRASHES HERE)  response = DirectCast(request.GetResponse(), HttpWebResponse)  '(CRASHES HERE)

            ' Get the response stream into a reader 

            reader = New StreamReader(response.GetResponseStream())

            responseString = reader.ReadToEnd

        Catch

        Finally

            If Not response Is Nothing Then response.Close()

        End Try



        Return responseString

    End Function
0 Kudos
RichardWatson
Frequent Contributor
What is the length?

Check out the following file:

C:\Program Files\ArcGIS\Server\framework\runtime\tomcat\conf\server.xml

This file seems to define a number of limits for the embedded web server used by ArcGIS Server:

    <Connector connectionTimeout="20000" maxHttpHeaderSize="65535" maxPostSize="10485760" port="6080" protocol="HTTP/1.1" redirectPort="6443" server=" "/>
0 Kudos
BobCarberry
New Contributor
The length is 24179. I don't seem to have that file, I'm running Server 10.0.
0 Kudos
RichardWatson
Frequent Contributor

        request = DirectCast(WebRequest.Create(baseUrl + input), HttpWebRequest)


Looks like you are putting the information in the URI and in the body.  Right?
0 Kudos
BobCarberry
New Contributor
Yes, I think so.
0 Kudos
RichardWatson
Frequent Contributor
Take the arguments out of the URI. 

Hopefully that should fix your size problem because the size of your URI should be less than 100 characters versus over 24,000.
0 Kudos
BobCarberry
New Contributor
Richard,

You are a gentleman and a scholar!  After almost a week of wrestling around with this, your suggestion worked! Thanks!

Here is the solution if any one is interested:

Perform a query on a layer in mapservice in vb.NET using the REST API:

baseUrl = "http://<Server Name>/ArcGIS/rest/services/<Map Service Name>/MapServer/<Layer ID>/query"

input =        "&geometry=" + <geometry> + _
                   "&geometryType=esriGeometryPolygon" + _
                   "&inSR=" + _
                   "&spatialRel=esriSpatialRelIntersects" + _
                   "&relationParam=" + _
                   "&objectIds=" + _
                   "&where=" + _
                   "&time=" + _
                   "&returnIdsOnly=false" + _
                   "&returnGeometry=true" + _
                   "&maxAllowableOffset=" + _
                   "&outSR=" + _
                   "&outFields=*" + _
                   "&f=json"

Private Shared Function PostIt(ByVal baseUrl As String, ByVal input As String) As String
        Dim responseString As String
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader

        Dim byteData() As Byte
        Dim postStream As Stream = Nothing

        request = DirectCast(WebRequest.Create(baseUrl), HttpWebRequest)
        ' Set type to POST 
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        ' Create a byte array of the data we want to send 
        byteData = UTF8Encoding.UTF8.GetBytes(input)
        ' Set the content length in the request headers 
        request.ContentLength = byteData.Length

        Try

            postStream = request.GetRequestStream()
            postStream.Write(byteData, 0, byteData.Length)
        Finally

            If Not postStream Is Nothing Then postStream.Close()
        End Try

    
        Try

            ' Get response 
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Get the response stream into a reader 

            reader = New StreamReader(response.GetResponseStream())

            responseString = reader.ReadToEnd

        Catch

        Finally

            If Not response Is Nothing Then response.Close()

        End Try



        Return responseString

    End Function
0 Kudos
AlanEpp
New Contributor II
Bob, thanks for posting your solution.  YOU saved ME a boatload of time and angst!
Al
0 Kudos