1. Larry Pettit
  2. PowerBuilder
  3. Friday, 16 December 2022 21:05 PM UTC

I am currently using HTTPClient.SendRequest("POST", string url) to send a REST API Call to a 3rd party application.  It works fine unless the total length of the URL is over about 2,000 characters which happens to be IIS's limit.  I could break it down into two completely separate SendRequests (some of the data with the first call and some with the second), but I was hoping someone could give me a better way.  It's hard to tell from the documentation which is the "old way" of doing things versus the "new way".  Any advice would be appreciated.  I am using PowerBuilder 2022 (newest version/build).  Following is the URL (with a few changes to characters for security reasons). Should I be using a different overload of the SendRequest function?  Other ideas?

 

http://kwiktag.pettitco.com/apiv2/Document/MetaDataUpdate/afjdlwic4-cf56-4fca-a92a-bf8e73856eda?DocId=&barcode=220073507&userName=LRPETTIT&token=7b4e18eb-f482-4d82-b613-023627699dac&exceptedPageCount=&includeEmpty=&scannedPageCount=&newValues=%3CArrayOfXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ECompany%20ID%3C%2FName%3E%3CValue%3E02%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVoucher%20Number%3C%2FName%3E%3CValue%3E25176%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVendor%20ID%3C%2FName%3E%3CValue%3E1176%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVendor%20Name%3C%2FName%3E%3CValue%3ELarry%20R.%20Pettit%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVendor%20Invoice%20Number%3C%2FName%3E%3CValue%3E12457809%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVendor%20Invoice%20Date%3C%2FName%3E%3CValue%3E12%2F15%2F22%2000:00:00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EImage%20Type%3C%2FName%3E%3CValue%3EVendor%20Invoice%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3EVendor%20Invoice%20Total%3C%2FName%3E%3CValue%3E2100.0000%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%201%20Account%3C%2FName%3E%3CValue%3E1300%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%202%20Account%3C%2FName%3E%3CValue%3E5000%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%203%20Account%3C%2FName%3E%3CValue%3E6910%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%204%20Account%3C%2FName%3E%3CValue%3E4997%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%205%20Account%3C%2FName%3E%3CValue%3E7100%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%206%20Account%3C%2FName%3E%3CValue%3E1201%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%201%20Amount%3C%2FName%3E%3CValue%3E100.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%202%20Amount%3C%2FName%3E%3CValue%3E200.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%203%20Amount%3C%2FName%3E%3CValue%3E300.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%204%20Amount%3C%2FName%3E%3CValue%3E400.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%205%20Amount%3C%2FName%3E%3CValue%3E500.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3CXFerMetadata%3E%3CName%3ELine%206%20Amount%3C%2FName%3E%3CValue%3E600.00%3C%2FValue%3E%3C%2FXFerMetadata%3E%3C%2FArrayOfXFerMetadata%3E

Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 8 February 2023 19:03 PM UTC
  2. PowerBuilder
  3. # 1

Here is how to post a large file. In this example, lblb_PostData contains the file data.

Blob lblb_PostData, lblb_PostPart
Integer li_rc, li_PartNum, li_PartLen = 1024

lnv_Http.SetRequestHeader("Content-Length", String(Len(lblb_PostData)))

// send the request
li_rc = lnv_Http.PostDataStart(ls_ServerURL)
If li_rc = 1 Then
	// post the data in parts
	do while li_rc = 1
		lblb_PostPart = BlobMid(lblb_PostData, li_PartNum * li_PartLen + 1, li_PartLen)
		li_rc = lnv_Http.PostData(lblb_PostPart, li_PartLen)
		li_PartNum ++
	loop
	lnv_Http.PostDataEnd()

	// get results
	ll_StatusCode = lnv_Http.GetResponseStatusCode()
	If ll_StatusCode = 200 Then
		// HTTP status 200 = OK
	End If
End If
Comment
  1. Thomas Rolseth
  2. Friday, 10 February 2023 06:21 AM UTC
Let's say my url is http://some.url.com/api/File/UploadTest/1234 (where 1234 is an ID of a record in the database) and my basic controller method in SnapDevelop is this:



[HttpPost]

public int UploadTest(string documentID)

{

return 0;

}

What would the controller arguments be to get the blob sent via PostData? I'm uncIear how to capture the blob inside the controller. I need a solution that will work with Word documents that can often be 50MB+.
  1. Helpful
  1. Roland Smith
  2. Friday, 10 February 2023 14:01 PM UTC
I'm not using SnapDevelop so I don't know.
  1. Helpful
There are no comments made yet.
Bruce Armstrong Accepted Answer Pending Moderation
  1. Saturday, 17 December 2022 01:08 AM UTC
  2. PowerBuilder
  3. # 2

If you're POSTing data to a web service, you would normally send the data in the body of the request, not as part of the URL.  That's why you're hitting the limit, because of the restriction on the size of a URL.

I would look at the documentation for the REST service in question to determine if the data should be send in the request body.

Comment
There are no comments made yet.
Larry Pettit Accepted Answer Pending Moderation
  1. Friday, 16 December 2022 22:51 PM UTC
  2. PowerBuilder
  3. # 3

Is this something the author of the REST API (a third party) has to have built support for to handle the reception of the data in pieces, or would it be expected to work universally with any REST call?

Comment
  1. Roland Smith
  2. Saturday, 17 December 2022 02:14 AM UTC
The receiving API will get it in one piece.
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 16 December 2022 21:27 PM UTC
  2. PowerBuilder
  3. # 4

There is a limit which is undocumented, I ran into it myself. You need to use the PostData methods. Here is a clip from the help file:

if lnv_HttpClient.PostDataStart("http://demo.appeon.com/PB/webapi_client/employee/102/photo") = 1 then
 for i = 1 to li_PackCount
  lblb_NextData = blobmid(lblb_photo, (i - 1) * 1024 + 1, 1024)
  li_rc = lnv_HttpClient.PostData(lblb_NextData, 1024)
  if li_rc <> 1 then exit
 next
end if

li_rc = lnv_HttpClient.PostDataEnd()

Comment
  1. Roland Smith
  2. Wednesday, 1 February 2023 13:11 PM UTC
The PostData example is from the help file. A couple months ago my client app was using SendRequest to post data. I discovered that there is a size limit to using SendRequest. I had to switch to the PostData method. There also seems to be a size limit on receiving response data. After a certain size you have to use ReadData. I don't know what the limits are, I didn't bother trying to test that. Maybe one of the Appeon developers can check their code and have the documentation writers add that to the help file.
  1. Helpful
  1. Thomas Rolseth
  2. Wednesday, 8 February 2023 18:48 PM UTC
What is li_PackCount in the example above? Is it the length of the blob (i.e. lblb_photo)?
  1. Helpful
  1. Roland Smith
  2. Wednesday, 8 February 2023 18:56 PM UTC
The help file never initialized li_PackCount so it isn't clear what it should be. Personally I would use 'do while li_rc = 1' and set li_rc to 1 before the loop. That would allow deleting the line with the exit.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.