Re: The remote server returned an error: (400) Bad Request.

Solved! Go to solution
rasith
Helper

The remote server returned an error: (400) Bad Request.

We are getting below error while execute this statement
request.GetRequestStream().Write(requestStringBytes

The remote server returned an error: (400) Bad Request.

12 REPLIES 12
rasith
Helper

Re: The remote server returned an error: (400) Bad Request.

While execute the getrequeststream statement we are getting below error <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid URL</h2>
<hr><p>HTTP Error 400. The request URL is invalid.</p>
</BODY></HTML>

rasith
Helper

Re: The remote server returned an error: (400) Bad Request.

Header details

------------------

{Authorization: Basic SDNOSVJHQ0NEQVowQ0VKUDg4S0oyMTFZUUxCV2lQZVo5dTBBaVpwWHYzZW1fd05oazpKUDdoR1dORkZjRjNIaEtPNUlYMQ==
ex-correlation-id: 7AQ76C44W95P_SC
Content-Type: application/json
Accept: application/json

}

 

We are getting

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid URL</h2>
<hr><p>HTTP Error 400. The request URL is invalid.</p>
</BODY></HTML>

in Merchant search

API_Products
Visa Developer Support Specialist

Re: The remote server returned an error: (400) Bad Request.

Hey @rasith,

 

The cause and resolution of the Bad Request 400 error could be due to a variety of reasons.

 

Check for the following:

  • The url has a space after the ?.
  • Whitespace issues, in general, anywhere in the url.
  • Ideally the following fields need to be checked for correctness:
    • URL
    • Query params

Or

 

  • The API endpoint you are trying to use only supports Two-Way SSL authentication. Please ensure you are not using any other token type.

 

Or

 

  • Invalid input found in the request payload.

 

If the error persists, please provide the following information:

1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body

Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.

 

Here's a link to the Visa Developer Error Codes which will be useful if you run into errors - https://developer.visa.com/pages/visa-developer-error-codes

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

rasith
Helper

Re: The remote server returned an error: (400) Bad Request.

Thanks Diana for your kind reply.  We have checked what you asked and comments are below;

 

Request URL is below
https://sandbox.api.visa.com/merchantsearch/v1/search
there is no white space and query parameters.

We are not using token type. Please kindly confirm us this end point needs to Two Way SSL. Because we created client side p12 certificate and key attached in configuration file.

 

Request Header

 

{Authorization: Basic SDNOSVJHQ0NEQVowQ0VKUDg4S0oyMTFZUUxCV2lQZVo5dTBBaVpwWHYzZW1fd05oazpKUDdoR1dORkZjRjNIaEtPNUlYMQ==
ex-correlation-id: 46L2MPH2645T_SC

}

Request Body


{"header": {"messageDateTime": "2019-09-15T06:02:59.340","requestMessageId": "CDISI_GMR_001","startIndex": "1"},"searchAttrList": {"merchantName": "ALOHA CAFE","merchantStreetAddress": "410 E 2ND ST","merchantCity": "LOS ANGELES","merchantState": "CA","merchantPostalCode": "90012","merchantCountryCode": "840","visaMerchantId": "11687107","visaStoreId": "125861096","businessRegistrationId": "196007747","acquirerCardAcceptorId": "191642760469222","acquiringBin": "486168"},"responseAttrList": ["GNSTANDARD"],"searchOptions": {"maxRecords": "2","matchIndicators": "true","matchScore": "true"}}

 

Using Post method.


We did not get any response details because if executing the statement of request.GetRequestStream() immediately it moved to exception.

We are using .Net to make connection and get response from API.

Please kindly check this and let us guide how to proceed further to solve this issue.

 

Thanks

Rasith

 

 

API_Products
Visa Developer Support Specialist

Re: The remote server returned an error: (400) Bad Request.

Hey @rasith,

 

Merchant Search uses Two-Way SSL.

 

Make sure to follow the guide step by step and in sequence to get a successful response. I've provided steps on how to configure Soap UI for a successful response and I've included example screenshots. Please also see the successful SOAP UI setup I have in the attachment XML file for Merchant Search and make sure to use your own VDP project credentials (username and password) and JKS file.

 

To access your project credentials, please login to your VDP account > My Account > Dashboard > project app > Credentials

Credentials dashboard.png

 

Also, please double check the SSL settings and make sure the keystore has all the necessary certificates imported. To start, this error usually occurs when your certificates are not sent. 

· Keystore is not setup. Certificates are not in the keystore:

For java keystore (jks) run keytool command and verify all the certificates have been imported on the keystore

· keytool -list -v -keystore keystore.jks

 

For a p12 execute the following openssl command:

· openssl pkcs12 -info -in keyStore.p12

· In SOAPUI check File->Settings->SSL Settings and make sure the KeyStore and KeyStore Password are populated in Soap UI

 

SSL Settings Clientkeystore.png

 

· Check SSL Info Tab in SOAP UI Response and verify you have a Local Certificate 1, Local Certificate 2 followed by Peer Certificate 1 and Peer Certificate 2

 

20190621 Peer Certificates.png

 

· In addition to that, if you are using SOAP UI, please make sure to select "Authenticate pre-emptively" under "Auth (Basic)" tab. Also, please double check in the request raw tab that the "Authentication Basic" is present.

 

20190621 Authenticate Pre-emptively.jpg

 

· Check request header and make sure Authorization: Basic has been populated with the base64 encoded username and password:

 

20190621 Authorization Basic.jpg

 

Please follow the Working with Visa APIs guide and read the Two-Way SSL (Mutual Authentication) guide: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl

 

Furthermore, please make sure you are using valid Test Data from your project app.

 

20190905 Test Data.png

 

20190613 Merchant Search Test Data.png

 

If the issue persists, please provide more information on the error you have received for further investigation. Please send the response request of the error received, screenshot and the Correlation ID. Please let us know if you have other questions.

 

Successful JSON Request:

{
"searchAttrList": {
"merchantName": "STARBUCKS",
"merchantCity": "SAN FRANCISCO",
"merchantState": "CA",
"merchantPostalCode": "94127",
"merchantCountryCode": "840"
},
"responseAttrList": [
"GNSTANDARD"
],
"searchOptions": {
"wildCard": [
"merchantName"
],
"maxRecords": "5",
"matchIndicators": "true",
"matchScore": "true",
"proximity": [
"merchantName"
]
},
"header": {
"requestMessageId": "Request_001",
"startIndex": "0",
"messageDateTime": "2019-08-20T18:18:40.903"
}
}

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: The remote server returned an error: (400) Bad Request.

Hey @rasith,

 

Here's a screenshot of the 200 OK I got from Soap UI for Merchant Search.

 

SOAP UI merchantsearch v1 200 ok.png

 

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

API_Products
Visa Developer Support Specialist

Re: The remote server returned an error: (400) Bad Request.

Hey @rasith,

 

Instead of using Soap UI, you can also start testing with the VDP Playground application, which is downloadable from your VDP project under the "Assets" section.

 

The VDP Playground is an application that makes testing VDP APIs easy and quick and it creates the JKS file for you quickly.

 

20190917 Assets VDP Playground.png

 

 

I got a successful response using the VDP Playground, refer to the screenshot below. Please note, to create the JKS file just browse for your public key (cert.pem) and private key and click on the JKS button. After you click on the JKS button a message will appear saying that your JKS file is created. Also, make sure to enter your credentials, host, port and EndPoint. You will also need to enable the Proxy.

20190917 VDP Playground merchantsearch v1 200 ok.png

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

rasith
Helper

Re: The remote server returned an error: (400) Bad Request.

Thanks Diana for your reply,

 

We tried with use of Visa Developer Center Playground. We gave all details from our dashboard. We have attached the Public and private keys.

We have given the .p12 certificate and password but not given jks. if we are running that we are getting below error. We are accessing this API from middle East region(United Arab Emirates). Is it possible to access this?

 

Error:

 

This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server (sandbox.api.visa.com)

API_Products
Visa Developer Support Specialist

Re: The remote server returned an error: (400) Bad Request.

Hey @rasith,

 

Can you please explain what you mean when you say "but not given jks"? You will only need to input your cert.pem (public key) and private key. After you input this into VDP, you will have to click on the "JKS" button, enter a password (e.g. Visa123) then enter the name of the JKS (e.g. clientkeystore) then a keystore will be created in the folder that you have saved the cert.pem and private key in. Make sure you create a folder on your local machine to put your cert.pem and private key in. 

 

Then you will also need to input your User ID and Password. 

 

If the error persists, please provide the following information:

1. End Point
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body

Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.

 




Thanks,

Diana



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.