cancel
Showing results for 
Search instead for 
Did you mean: 

Getting error response while trying to access REST webservice through Powerbuilder

Former Member
0 Kudos


Hi Team,

I am trying to access a rest webservice through powerbuilder 12.5(.net).The rest webservice is secured through basic authentication.I am passing the userid and password through powerbuilder to acess the service,But its returning an error .But while i am trying to accss the same REST webservice through SOAPUI, i am able to get the response.

Please find the below line of code which i have written in powerbuilder.

p_testcleint2 lp_rest
string ls_string

lp_rest=create p_testcleint2

PBWebHttp.WebClientCredential lsCredential             //configure credentials
lsCredential = create PBWebHttp.WebClientCredential
lsCredential.AccessAuthentication = PBWebHttp.AuthenticationMode.Basic!
lsCredential.Password='Pa$$word1!'
lsCredential.Username='admin'
lp_rest.restConnectionObject.ClientCredential = lsCredential  //add credentials to connection


try
   lp_rest.PostMessage()
 
catch (System.Exception ee)
  messagebox("Failure",string(ee.Message))
end try

Error i am getting as below :

The remote server returned an error:(401) unauthorized.

Can you please let me know why this error is coming or do i need to any extra paramert in the lsCredential to handle this.

Thanks in advance.

Regards

Subrat

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Subrat and all,

any luck in solving the error -401 ?

I also have the same problem.

Best,

Marco

former_member190719
Active Contributor
0 Kudos

Normally a 401 error is what you are *supposed* to get with basic authentication, and it's only after that error that the client then sends the authentication details.

HttpClient Basic Authentication | Baeldung

What may be happening is that the server has been configured to only accept Direct Authentication (rather than Challenge/Response).  In that case you need to get the PreAuthentication property set for the web request.  That's what will tell it to send the credentials on the first request rather than waiting for the challenge.

HttpWebRequest.PreAuthenticate Property

Former Member
0 Kudos

Hi Bruce,

thanks for your comment.

The point is, I went through the same Werde's article on calling RESTful WS from PB.NET (12.6 build 3506 my setup) at

http://www.codeproject.com/Articles/271588/RESTful-Web-Services-A-Quick-Start-How-to-Guide

but it seems that listing 3 always returns error -401 (user unauthorised) when accessing the test service at http://phprestsql.sourceforge.net/tutorial/user.

On the other hand, if the service is called from Chrome ARC or Fiddler, the authentication works.

To tell the truth, when I check the PB HTTP request with Fiddler, looks like the header set in PB is empty.

I've also tried a different REST service (e.g. https://api.github.com/user) but same error.

Is it a bug in the PB.NET WCF infrastructure?

Best,

Marco

Former Member
0 Kudos

hi again.

In the attempt to share some thoughts and possibly find a solution, I have uploaded the simplest PB.NET test case at

https://www.dropbox.com/s/z7xfpab52nv20gs/restful.zip?dl=0

(set your github user/pwd in the proxy object's constructor).

My test server is https://api.github.com/user, so "direct authentication" or "challenge/response" configurations are not an issue here: authentication against Github simply works from Fiddler4 but it does not from PB.

This picture

https://www.dropbox.com/s/p5neoyi4y5z9hw6/fiddler.png?dl=0

shows that when the RESTful service is called from Fiddler4 the HTTP header contains basic authentication info, whereas the same request from PB does not.

Any help is truly appreciated.

Best,

Marco

Former Member
0 Kudos

Hi  ;

  Did you  also set the format ....

lp_rest.RequestMessageFormat    = PBWebHttp.WebMessageFormat.Xml!
lp_rest.ResponseMessageFormat = PBWebHttp.WebMessageFormat.Xml!

Regards ... Chris

Former Member
0 Kudos

Hi Subrata;

  Have you tried running something like Fiddler2 to see exactly what the WS exchange & eventual failure might be?

FYI: Fiddler free web debugging proxy

Regards ... Chris

Former Member
0 Kudos

Hi Chris,

Thanks for the reply.

Yes i checked -in fiddler, the basic authentication request is not generating in the fiddler.

In the same Rest service if i turned off the basic authentication then call is happening in Powerbuilder and its displaying in fiddler also.

Regards

Subrat

Former Member
0 Kudos

Hi ,,

Can anybody have any thoughts on this.

Regards

Subrat