Re: Bad request

Reighn
Helper

Bad request

Hi, Im getting a bad request while doing a test Fund Transfer. I already used the example code but with no luck I can't seem to make a successful transaction. Please help! Thank you in advance.

 

Cheers!

3 REPLIES 3
vivek241
Visa Employee

Re: Bad request

Hi Reighn,

 

Can you share the exact request/code that you're trying to use?

Reighn
Helper

Re: Bad request

I used the sample code visa provided and also I generated the certificate needed. So here is the code.

 

string requestURL = ConfigurationManager.AppSettings["visaUrl"] + path;
string userId = ConfigurationManager.AppSettings["userId"];
string password = ConfigurationManager.AppSettings["password"];
string certificatePath = ConfigurationManager.AppSettings["cert"];
string certificatePassword = ConfigurationManager.AppSettings["certPassword"];
string statusCode = "";
LogRequest(requestURL, requestBodyString);
// Create the POST request object
HttpWebRequest request = WebRequest.Create(requestURL) as HttpWebRequest;
request.Method = method;
if (method.Equals("POST") || method.Equals("PUT"))
{
request.ContentType = "application/json";
// Load the body for the post request
var requestStringBytes = Encoding.UTF8.GetBytes(requestBodyString);
request.GetRequestStream().Write(requestStringBytes, 0, requestStringBytes.Length);
}
request.Accept = "application/json";

// Add headers
string authString = userId + ":" + password;
var authStringBytes = Encoding.UTF8.GetBytes(authString);
string authHeaderString = Convert.ToBase64String(authStringBytes);
request.Headers["Authorization"] = "Basic " + authHeaderString;
request.Headers["x-correlation-id"] = GetCorrelationId();

// Add certificate
var certificate = new X509Certificate2(certificatePath, certificatePassword);
request.ClientCertificates.Add(certificate);

try
{
// Make the call
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
LogResponse(testInfo, response);
statusCode = response.StatusCode.ToString();
}
}
catch (WebException e)
{
if (e.Response is HttpWebResponse)
{
HttpWebResponse response = (HttpWebResponse)e.Response;
LogResponse(testInfo, response);
statusCode = response.StatusCode.ToString();
}
}
return statusCode;

 

Thanks!

 

Cheers!

vivek241
Visa Employee

Re: Bad request

Hi Reighn,

 

The code seems to be working fine.

The 400 response must be because of an incorrect value in the request payload.

Which API are you trying with what payload?

 

Thanks,

Vivek