View Single Post
  #2 (permalink)  
Old 12-17-08, 13:39
amberdextrous amberdextrous is offline
Registered User
 
Join Date: Dec 2008
Posts: 3
Asp.net, Vb, Get/post

Let me clarify...this is an ASP.NET web service.

I got my Find function working, and I am now able to run queries against the database using HTTP GET and the results are returned to me as XML. However, I am still having a problem with adding new records. I can add a new record with GET, but not POST. From my understanding, URIs have a length limit, and I've read that POST can be used in place of GET to avoid this limitation. I tried implementing a POST function based on sample code I saw, but I have a feeling I did it completely wrong. Like I said, I'm new to web services so forgive me.

This code works:

Code:
<WebMethod()> _
    Public Function Find() As String
        Dim uri As New Uri("http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-dso_xml&field1=value1&-find")
        Dim credentials As NetworkCredential

        If (uri.Scheme = uri.UriSchemeHttp) Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Get
            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            response.Close()
            Return xml
        End If
    End Function
And this code works:

Code:
<WebMethod()> _
<WebMethod()> _
    Public Function AddRecordWithHTTPGet() As String
        Dim uri As New Uri("http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-fmp_xml&field2=value2&-new")

        Dim credentials As NetworkCredential

        If (uri.Scheme = uri.UriSchemeHttp) Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Get
            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            response.Close()
            Return xml
        End If
    End Function
This code DOESN'T work:

Code:
<WebMethod()> _
    Public Function AddRecordWithHTTPPost()
        ' I get a "Format file not found" error:
        Dim uri As New Uri("http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-fmp_xml&-lay=webdown")
        Dim param1 As String = "field3=value3&-new"

        Dim credentials As NetworkCredential

        If uri.Scheme = uri.UriSchemeHttp Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Post
            request.ContentLength = param1.Length
            request.ContentType = "application/x-www-form-urlencoded"

            Dim writer As New StreamWriter(request.GetRequestStream)
            writer.Write(param1)
            writer.Close()

            Dim oResponse As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(oResponse.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            oResponse.Close()
            Return xml
        End If

    End Function
I think I read somewhere that adding FileMaker records can only be done with GET. Yet, when I view the web-enabled database in the browser and click "New record", a blank form comes up and when I left-click and select "View source code", FORM METHOD=POST is in the code. So there must be a way to do it in ASP.NET. Does anyone know how?
Reply With Quote