HTTP Post help - Part 2

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

HTTP Post help - Part 2

Post by TrevorDowdle » Thu Jul 12, 2012 5:34 pm

The Content type should be - application/x-www-form-urlencoded
The encoding should be - utf-8

I should be good with the Content-type because it defaults to application/x-www-form-urlencoded
I wonder if i encoding to utf8 correctly because when I return IT i am still getting a server error.

But if I take the value of myData and post it using a REST test website it works.

Code: Select all

put uniEncode(myData,"utf8") into myData  // encoding utf-8 

post myData to URL "http//secureexamplecom/InterfaceV2/testaspx"
Here is the value of my header data

POST /InterfaceV2/testaspx HTTP/1.1
Host: secureexamplecom
User-Agent: LiveCode (MacOS)
Content-Length: 5344
Content-Type: application/x-www-form-urlencoded

Am I missing something? Do I need to add the utf-8 encoding to the header data somehow instead?

Here is a screen shot of the REST test website where the same content(myData) is working.

Apparently its not working because of permissions but if you go to this url you can see it. (add the . before com and http)

[img]i1146.photobucketcom/albums/o525/TrevorDowdle/ScreenShot2012-07-12at102756AM.png[/img]

Thanks

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Thu Jul 12, 2012 6:06 pm

Trevor-

I don't know why you started a new thread for this. It makes it impossible to get any context.

Are you urlencoding myData? Or just uniEncoding it?

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: HTTP Post help - Part 2

Post by shaosean » Thu Jul 12, 2012 7:36 pm

TrevorDowdle wrote:I wonder if i encoding to utf8 correctly because when I return IT i am still getting a server error.

Code: Select all

put urlEncode(uniEncode(myData,"utf8")) into myData  // encoding utf-8 
post myData to URL "http//secureexamplecom/InterfaceV2/testaspx"

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Thu Jul 12, 2012 9:51 pm

Sorry I probably should have kept it on the same thread.

I was just uniEncoding myData.

Code: Select all

put urlEncode(uniEncode(myData,"utf8")) into myData  // encoding utf-8 
post myData to URL "http//secureexamplecom/InterfaceV2/testaspx"
Hey shaosean, I just tried the urlEncode on myData but unfortunately I still got a server error.. :(

Looks like i'm one step closer though..

Any other ideas why it might not be posting correctly?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Thu Jul 12, 2012 10:14 pm

OK - your header says you're going to be sending urlEncoded data, so that's what you should be doing.
Are you posting www-form data? That's what your header says.
What server error are you getting?

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: HTTP Post help - Part 2

Post by shaosean » Fri Jul 13, 2012 1:11 am

TrevorDowdle wrote:Any other ideas why it might not be posting correctly?
post code + post error = better help..

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Fri Jul 13, 2012 4:29 pm

Are you posting www-form data? That's what your header says.
I am posting an xml file/string like the following. Do I need to change my header?

Code: Select all

put "RxInput=<?xml version='1.0' encoding='utf-8'?>" & cr & \
         "<NCScript xmlns='httpsecureexamplecominterfaceV2' xmlns:NCStandard='httpsecureexamplecominterfaceV2:NCStandard' xmlns:xsi='http//wwww3org/2001/XMLSchema-instance'>" & cr & \
   "<Credentials>" & cr & \
         "<partnerName>AltaPoint</partnerName>" & cr & \
         "<name>b1803082a79c</name>" & cr & \
         "<password>d632172ca40d</password>" & cr & \
         "<productName>Practice Management</productName>" & cr & \
         "<productVersion>V10</productVersion>" & cr & \
         "</Credentials>" & cr & \
         "<UserRole>" & cr  & \
         "<user>LicensedPrescriber</user>" & cr & \
         "<role>doctor</role>" & cr & \
         "</UserRole>" & cr & \
         "<Destination>" & cr & \
         "<requestedPage>compose</requestedPage>" & cr & \
         "</Destination>" & cr & \
         "<Account ID='AP1'>" & cr & \
         "<accountName>Creekside Clinic</accountName>" & cr & \
         "<siteID>4686</siteID>" & cr & \
         "<AccountAddress>" & cr & \
         "<address1>1100 E. Avenue</address1>" & cr & \
         "<address2>Suite 101</address2>" & cr & \
         "<city>City</city>" & cr & \
         "<state>UT</state>" & cr & \
         "<zip>84047</zip>" & cr & \
         "<country>US</country>" & cr & \
         "</AccountAddress>" & cr & \
         "<accountPrimaryPhoneNumber>(801)555-1122</accountPrimaryPhoneNumber>" & cr & \
         "<accountPrimaryFaxNumber>(801)555-1123</accountPrimaryFaxNumber>" & cr & \
         "</Account>" & cr & \
         "<Location ID='SDAF'>" & cr & \
         "<locationName>Music</locationName>" & cr & \
         "<LocationAddress>" & cr & \
         "<address1>200 West 300 North</address1>" & cr & \
         "<address2></address2>" & cr & \
         "<city>City</city>" & cr & \
         "<state>UT</state>" & cr & \
         "<zip>84731</zip>" & cr & \
         "<country>US</country>" & cr & \
         "</LocationAddress>" & cr & \
         "<primaryPhoneNumber>(334)553-2343</primaryPhoneNumber>" & cr & \
         "<primaryFaxNumber>(889)909-8777</primaryFaxNumber>" & cr & \
         "<pharmacyContactNumber>(334)553-2343</pharmacyContactNumber>" & cr & \
         "</Location>" & cr & \
         "<LicensedPrescriber ID='AF'>" & cr & \
         "<LicensedPrescriberName>" & cr & \
         "<last>Flores</last>" & cr & \
         "<first>Alicia</first>" & cr & \
         "<middle></middle>" & cr & \
         "</LicensedPrescriberName>" & cr & \
         "<dea>11111111111111</dea>" & cr & \
         "<upin></upin>" & cr & \
         "<licenseState>UT</licenseState>" & cr & \
         "<licenseNumber>111111111111111111</licenseNumber>" & cr & \
         "<npi>54321</npi>" & cr & \
         "<freeformCredentials></freeformCredentials>" & cr & \
         "</LicensedPrescriber>" & cr & \
         "<Patient ID='ABBOT00001'>" & cr & \
         "<PatientName>" & cr & \
         "<last>Abbott</last>" & cr & \
         "<first>Mo</first>" & cr & \
         "<middle>K</middle>" & cr & \
         "</PatientName>" & cr & \
         "<medicalRecordNumber>123456</medicalRecordNumber>" & cr & \
         "<PatientAddress>" & cr & \
         "<address1>150 N 8900 E</address1>" & cr & \
         "<address2></address2>" & cr & \
         "<city>Creekside</city>" & cr & \
         "<state>UT</state>" & cr & \
         "<zip>84281</zip>" & cr & \
         "<country>US</country>" & cr & \
         "</PatientAddress>" & cr & \
         "<PatientContact>" & cr & \
         "<homeTelephone>(   )   -</homeTelephone>" & cr & \
         "</PatientContact>" & cr & \
         "<PatientCharacteristics>" & cr & \
         "<dob>19970422</dob>" & cr & \
         "<gender>M</gender>" & cr & \
         "</PatientCharacteristics>" & cr & \
         "<PatientFreeformHealthplans>" & cr & \
         "<healthplanName>Blue Cross Blue Shield</healthplanName>" & cr & \
         "</PatientFreeformHealthplans>" & cr & \
         "<PatientFreeformHealthplans>" & cr & \
         "<healthplanName>Medicare</healthplanName>" & cr & \
         "</PatientFreeformHealthplans>" & cr & \
         "<PatientFreeformHealthplans>" & cr & \
         "<healthplanName>United Health</healthplanName>" & cr & \
         "</PatientFreeformHealthplans>" & cr & \
         "</Patient>" & cr & \
         "</NCScript>" into myData

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Fri Jul 13, 2012 5:23 pm

I'm hoping this will help, I used Fiddler to track the post request where is worked and this is what it looks like. (note I have changed some of the urls in the past but not in this header data..)


POST /InterfaceV7/RxEntry. aspx HTTP/1.1
Host: secure . newcropaccounts . com
Proxy-Connection: keep-alive
Content-Length: 2672
Origin: chrome-extension://cokgbflfommojglbmbpenpphppikmonn
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
Content-Type: application/x-www-form-urlencoded
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP . NET_SessionId=vr01f4x3bjb1wj3abhzzzo4y; UserCulture=en-US; ClickThroughSession=Y; RX.Web.App=6CD1F63975C1060E8540CB8B8488E7E2347A8B157DCA6486518AEFB72E1C58FA412DC0EC7D872AE3968A48E72B7FF50D7275E85DF1218EC05A1A009B0A5D1EE211DB92698F3D13C4221EF7990FBCDE0D694D20620DD402B64D4E9511C6F233AC623B67F6; LogOnPageUrl=/Account/AltaPoint

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Fri Jul 13, 2012 6:25 pm

Well, you're telling the server that you're posting www-form-urlencoded data, but it looks like you're just posting xml data. If the server only accepts www-form-urlencoded data then I think you want to prepend "<nameOfVariable>&" to the urlencoded string in order to create a name-value pair for the server. OTOH, if you want to send just the xml data to the server and the server will accept that as a post statement then you should change the Content-Type.

The next step should be to use Fiddler to see not only the working header, but what the actual working posted data looks like. That should tell you what the formatting should be.

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Fri Jul 13, 2012 6:52 pm

Yeah, that data is basically the XML file the only difference is that it has "RXInput=" at the first. So maybe thats why it needs to treat it as urlencoded data.. From the rest website where I am posting it, the header is set to www-form-urlencoded so I would imagine I'm okay there..

Any other ideas? I'll post the raw data form fiddler that shows the hole data, hopefully it will help.

I'm still confused on what I can do.

I can try to set the header data to be exactly like the working header.. i.e.

set the httpHeaders to "Accept-Encoding: gzip,deflate,sdch"

etc..

But i'm confused at what to put for "User-Agent:" "Origin:" etc..

Here is the raw data from Fiddler

POST http// securenewcropaccountscom/InterfaceV7/RxEntryaspx HTTP/1.1
Host: securenewcropaccountscom
Proxy-Connection: keep-alive
Content-Length: 2672
Origin: chrome-extension//cokgbflfommojglbmbpenpphppikmonn
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11
Content-Type: application/x-www-form-urlencoded
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASPNET_SessionId=vr01f4x3bjb1wj3abhzzzo4y; UserCulture=en-US; ClickThroughSession=Y; RX.Web.App=6CD1F63975C1060E8540CB8B8488E7E2347A8B157DCA6486518AEFB72E1C58FA412DC0EC7D872AE3968A48E72B7FF50D7275E85DF1218EC05A1A009B0A5D1EE211DB92698F3D13C4221EF7990FBCDE0D694D20620DD402B64D4E9511C6F233AC623B67F6; LogOnPageUrl=/Account/AltaTest

RxInput=<?xml version='1.0' encoding='utf-8'?>
<NCScript xmlns=' http// securenewcropaccountscom/interfaceV7' xmlns:NCStandard=' http// securenewcropaccountscom/ interfaceV7:NCStandard' xmlns:xsi=' http// wwww 3org/2001/XMLSchema-instance'>
<Credentials>
<partnerName>AltaTest</partnerName>
<name>3c9a75ba-fb01-4356-86d4-b1803082a79c</name>
<password>752e0b24-d931-42be-9f47-d632172ca40d</password>
<productName>AltaPoint Practice Management</productName>
<productVersion>V10</productVersion>
</Credentials>
<UserRole>
<user>LicensedPrescriber</user>
<role>doctor</role>
</UserRole>
<Destination>
<requestedPage>compose</requestedPage>
</Destination>
<Account ID='AP1'>
<accountName>Creekside Clinic</accountName>
<siteID>4686</siteID>
<AccountAddress>
<address1>Union Avenue</address1>
<address2>Suite 101</address2>
<city>City</city>
<state>UT</state>
<zip>84047</zip>
<country>US</country>
</AccountAddress>
<accountPrimaryPhoneNumber>(801)555-1122</accountPrimaryPhoneNumber>
<accountPrimaryFaxNumber>(801)555-1123</accountPrimaryFaxNumber>
</Account>
<Location ID='SDAF'>
<locationName>Music</locationName>
<LocationAddress>
<address1>200 West 300 North</address1>
<address2></address2>
<city>City</city>
<state>UT</state>
<zip>84731</zip>
<country>US</country>
</LocationAddress>
<primaryPhoneNumber>(334)553-2343</primaryPhoneNumber>
<primaryFaxNumber>(889)909-8777</primaryFaxNumber>
<pharmacyContactNumber>(334)553-2343</pharmacyContactNumber>
</Location>
<LicensedPrescriber ID='AF'>
<LicensedPrescriberName>
<last>Flores</last>
<first>Alicia</first>
<middle></middle>
</LicensedPrescriberName>
<dea>11111111111111</dea>
<upin></upin>
<licenseState>UT</licenseState>
<licenseNumber>111111111111111111</licenseNumber>
<npi>54321</npi>
<freeformCredentials></freeformCredentials>
</LicensedPrescriber>
<Patient ID='ABBOT00001'>
<PatientName>
<last>Abbott</last>
<first>Mo</first>
<middle>K</middle>
</PatientName>
<medicalRecordNumber>123456</medicalRecordNumber>
<PatientAddress>
<address1>150 N 8900 E</address1>
<address2></address2>
<city>Creekside</city>
<state>UT</state>
<zip>84281</zip>
<country>US</country>
</PatientAddress>
<PatientContact>
<homeTelephone>( ) -</homeTelephone>
</PatientContact>
<PatientCharacteristics>
<dob>19970422</dob>
<gender>M</gender>
</PatientCharacteristics>
<PatientFreeformHealthplans>
<healthplanName>Blue Cross Blue Shield</healthplanName>
</PatientFreeformHealthplans>
<PatientFreeformHealthplans>
<healthplanName>Medicare</healthplanName>
</PatientFreeformHealthplans>
<PatientFreeformHealthplans>
<healthplanName>United Health</healthplanName>
</PatientFreeformHealthplans>
</Patient>
</NCScript>

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Fri Jul 13, 2012 7:25 pm

The issue isn't with it being urlencoded, it's with the "form" part. If you're telling the server that you're sending www-form-urlencoded data then the data you're posting has to be in the format of name-value pairs. That's how the server will associate the posted data with the variables it expects to see. So instead of

Code: Select all

post myData to URL "http//secureexamplecom/InterfaceV2/testaspx"
try

Code: Select all

post "RXInput=" & myData to URL "http//secureexamplecom/InterfaceV2/testaspx"
That way the server knows that it should associate the xml data with the RXInput variable that, in other circumstances, would be posted from a web page form.

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Fri Jul 13, 2012 8:39 pm

Brilliant! That makes sense.


I'm really sorry to petition for your knowledge once more but now here is the the server error I get after implementing your fix.

So from what I understand the server is having an issue parsing the name element.. But I guess its not very telling because when I delete the name element completely it still gives me the same error.

Going to be looking into it, hoping the error makes sense, so you might be able to determine whats happening.

Thanks

A technical error has been automatically reported to your EMR/PM vendor. Contact them for more information. MSG 3 - RxInput XML parse error:
Please check the specified element name and value below for unusual characters and leading or trailing spaces.

Name cannot begin with the '.' character, hexadecimal value 0x00. Line 1, position 2.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Fri Jul 13, 2012 9:02 pm

OK - sounds like you're most of the way there. The ' character is an apostrophe. The fact that you're getting an "RXInput" error is good - the server is trying to apply the data in the right place. Offhand, I'd say don't uniEncode the data and see what happens - that may be adding an extra level of translation that isn't strictly necessary in this case for the xml data. And keep an eye on what Fiddler says you're sending vs what you expect to be sending.

TrevorDowdle
Posts: 16
Joined: Tue Jul 10, 2012 4:37 pm

Re: HTTP Post help - Part 2

Post by TrevorDowdle » Fri Jul 13, 2012 9:29 pm

Thanks a bunch!

Okay removing the uniEncode Fixed it.

Here is the response.. Which is awesome! Because like you suggested I checked with fiddlers and looked at the response and it is the exact same! :D

But when I do it in Chrome after I get this response I get redirected to another page (which I will show underneath)
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/Pages/ComposeRx.aspx">here</a>.</h2>
</body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http//wwww3org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http// wwww3org/1999/xhtml">
<head><title>
RxEntry
</title></head>
<body>
<form method="post" action="RxEntryaspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgL+raDpAgLs0bLrBkSMvTBSCbu+/8aJa5X1zpy1cLk6" />
<div>
<textarea name="TextBox1" rows="2" cols="20" id="TextBox1">
Original XML:
<?xml version='1.0' encoding='utf-8'?>
<NCScript xmlns='http//securenewcropaccountscom/interfaceV7' xmlns:NCStandard='http//securenewcropaccountscom/interfaceV7:NCStandard' xmlns:xsi='http// wwww3org/2001/XMLSchema-instance'>
<Credentials>
<partnerName>AltaTest</partnerName>
<productName>AltaTest Management</productName>
<productVersion>V10</productVersion>
</Credentials>
<UserRole>
<user>LicensedPrescriber</user>
etc.. etc..
</div>
</form>
</body>
</html>
Now here is the page I get redirected to (just a small portion of it because it is huge..)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http//wwww3org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http//wwww3org/1999/xhtml">
<head id="ctl00_Head1"><title>
Compose Rx
</title><link href="../App_Themes/Default/Default.css" type="text/css" rel="stylesheet" /></head>
<body id="ctl00_pageBody">
<form method="post" action="ComposeRx.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['aspnetForm'];
if (!theForm) {
theForm = document.aspnetForm;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
Now my only question is if I were to load that first html response in a browser it would automatically redirect me to the 2nd page?

Thanks again, you have been great help.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: HTTP Post help - Part 2

Post by mwieder » Fri Jul 13, 2012 9:33 pm

Now my only question is if I were to load that first html response in a browser it would automatically redirect me to the 2nd page?
no, not automatically. There's a libURL property you can set to enable this, though. I can't recall it off the top of my head and I don't have access to the docs at the moment. I'll dig it up when I can unless someone else chimes in first.

Post Reply