1. Yuri Denshchik
  2. PowerBuilder
  3. Thursday, 19 April 2018 22:11 PM UTC

We are trying to upload a file to a Web Server using new PB HttpClient object. So far no luck. Here is java code that we trying to migrate to PB:

            connection.setRequestMethod("POST");
            connection.setRequestProperty("Connection", "Keep-Alive");
            connection.setRequestProperty("User-Agent", "Android Multipart HTTP Client 1.0");
            connection.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary);
            
            outputStream = new DataOutputStream(connection.getOutputStream());
            outputStream.writeBytes(twoHyphens + boundary + lineEnd);
            outputStream.writeBytes("Content-Disposition: form-data; name=\"" + filefield + "\"; filename=\"" + q[idx] +"\"" + lineEnd);
            outputStream.writeBytes("Content-Type: " + contentType + lineEnd);
            outputStream.writeBytes("Content-Transfer-Encoding: binary" + lineEnd);
            outputStream.writeBytes(lineEnd);
            
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];
            
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            while(bytesRead > 0) {
                outputStream.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }

Bruce Armstrong Accepted Answer Pending Moderation
  1. Friday, 20 April 2018 17:48 PM UTC
  2. PowerBuilder
  3. # 1

What does your PowerBuilder code look like?

What error messages, if any, are you getting?  What is failing?

Comment
  1. Yuri Denshchik
  2. Monday, 23 April 2018 18:40 PM UTC
Bruce,



Here is a PB Code:



HttpClient luo_httpClient



int li_ret



long ll_ret, ll_length



 



as_error = ""



ll_length = len(ab_blob)



luo_httpClient = uf_getHttpClient()



luo_httpClient.SetRequestHeader("Content-Length", string(ll_length))



do 



 



li_ret = luo_httpClient.PostDataStart(as_url) 



if li_ret > 1 then exit



 



li_ret = luo_httpClient.PostData(ab_blob, ll_length)



if li_ret > 1 then exit



 



li_ret = luo_httpClient.PostDataEnd()



 



loop while false



 



destroy luo_httpClient



 



return li_ret



 



Here is error from the server:



11:29:32,456 ERROR [org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler]

 (default task-27) Exception occurred during processing request: Illegal charact

er ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed betwe

en tokens

 at [Source: java.io.InputStreamReader@96e9d3f; line: 1, column: 2]: org.codehau

s.jackson.JsonParseException: Illegal character ((CTRL-CHAR, code 0)): only regu

lar white space (\r, \n, \t) is allowed between tokens

 at [Source: java.io.InputStreamReader@96e9d3f; line: 1, column: 2]

        at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1433)

 [jackson-core-asl-1.9.13.jar:1.9.13]

  1. Helpful
  1. Alfredo Aldama
  2. Wednesday, 25 April 2018 03:25 AM UTC
Hola,



Mis comentarios:



 1)  Considero que te hacen faltan encabezados (missing headers, add same the code on java) 



 2)  El ciclo me parece no necesario(No Loop)  porque estas mandando todo el archivo, en tu codigo Java estas enviando partes( size of buffer) 



 3)  Especifica que estas enviando (application/json)



Saludos !!



 



 



 



 



 

  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.