× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello Jay,

You say this isn't a big deal, but to me, it's huge. If I don't know how you are SUPPOSED to send the data, I can't tell you how to code the same thing in HTTPAPI.

The manual for CURLOPT_POSTFIELDS says that if you pass an array, it'll use a multipart/form-data encoding. I found that, here:
http://php.net/manual/en/function.curl-setopt.php

That's the critical piece of information that we didn't have before...

HTTPAPI has a multipart/form-data encoder as well, but it works differently because this technique is often used to upload files, and RPG's strings (at least, at the time I wrote this support) are too small to work nicely with file uploads. So what you do is use the encoder to build a temporary file in the IFS, and then you can upload that file.

This is off the top of my head, I don't have time to actually code it up and test it right now, but hopefully will get you going in the right direction.

http_tempfile() returns a temporary (unique) filename in the IFS.

http_mfd_encoder_open() lets you build a multipart/form-data encoded document in any IFS filename. We'll use the temporary one we generate with http_tempfile() for this.

http_mfd_encoder_addvar_s() can be used to add small strings to the encoded data. http_mfd_encoder_addvar() can be used (with pointer support) to add larger strings.

http_mfd_encoder_addstmf() can be used to add a document from the IFS (i.e. your XML document).

http_mfd_encoder_close() frees up temporary memory that was used during the encoding process. So you'd do something like this:


// get temporary file name
filetopost = http_tempfile();

// create multipart/form-data encoder
// in temporary IFS file
enc = http_mfd_encoder_open( filetopost
: 'multipart/form-data');

// add code and api_key
http_mfd_encoder_addvar_s( enc
: 'code'
: '[YOUR CODE]');

http_mfd_encoder_addvar_s( enc
: 'api_key'
: '[YOUR KEY]');

// add XML document
http_mfd_encoder_addstmf( enc
: 'data'
: '/path/to/import.xml'
: 'application/xml');


// finished encoding!
http_mfd_encoder_close(enc);


// now do post:
rc = http_url_post_stmf( 'http://the-url-goes-here'
: filetopost
: fileforresult
: 60
: *omit
: 'multipart/form-data' );

// delete temp file
unlink(filetopost);

// handle errors
if rc <> 1;
// handle error
endif;

... etc ...


does that help?



On 7/9/2013 3:04 PM, tegger@xxxxxxxxxxx wrote:


They're using curl_exec and a few curl_setopt functions to build it up in memory.



$ch = curl_init ($urltopost);

curl_setopt ($ch, CURLOPT_POST, true);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$returndata = curl_exec ($ch);







This piece is not a big deal.



We don't have PHP on the iseries, so it has to go through RPG. I have your LIBHTTP on the system now. Just trying to link it all together.





Jay





----- Original Message -----


From: "Scott Klement" <rpg400-l@xxxxxxxxxxxxxxxx>
To: "RPG programming on the IBM i (AS/400 and iSeries)" <rpg400-l@xxxxxxxxxxxx>
Sent: Tuesday, July 9, 2013 4:01:52 PM
Subject: Re: http_url_post_xml and REST

Hello,

The sample code you provided just creates an array in a PHP script. It
does not send it anywhere... presumably, there's code later in the
program that does the actual POST.

Can you show us that code? That will help me understand what this is doing.

-SK

On 7/9/2013 2:38 PM, tegger@xxxxxxxxxxx wrote:


<?php

$urltopost = "https://[ServerName]/orders/api/add_order";;

$datatopost = array (

"code" => "[YOUR CODE]",

"api_key" => "[YOUR KEY]",

"data" => file_get_contents("import.xml"),

);



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.