Log in or register to post comments

400 Bad Request

August 27, 2014 - 2:47pm #1

I am using C# code that previously worked, I have seen the target created by the below code in the cloud database.  I tried running this code a couple of days later, now I get a "400 Bad Request" on the hwr.GetResponse call.  My C# code (I have replaced the security keys with dummy values):

public void AddTarget(byte[] bData)

{

string json = "{\"name\":\"ffxtarget1\",\"width\":\"320.0\",\"image\":\"" + Convert.ToBase64String(bData) + "\"}";

string dateValue = DateTime.UtcNow.ToString("R");

HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create("https://vws.vuforia.com/targets");

hwr.Date = DateTime.Parse(dateValue);

hwr.Headers.Add("Authorization", "VWS xyzkey:" + TmsSignature("abckey", json, dateValue));

hwr.ContentType = "application/json";

hwr.Method = "POST";

using (StreamWriter sw = new StreamWriter(hwr.GetRequestStream()))

{

sw.Write(json);

sw.Flush();

sw.Close();

}

HttpWebResponse hresponse = (HttpWebResponse)hwr.GetResponse();

StreamReader sr = new StreamReader(hresponse.GetResponseStream());

string srData = sr.ReadToEnd();

Console.WriteLine(srData);

File.WriteAllText(@"C:\Temp\zzzrav.txt", srData);

}

 

public string TmsSignature(string key, string jsonData, string dateValue)

{

MD5 md5 = MD5.Create();

byte[] bData = md5.ComputeHash(Encoding.ASCII.GetBytes(jsonData));

StringBuilder sb = new StringBuilder();

for (int iloop = 0; iloop < bData.Length; iloop++)

{

sb.Append(bData[iloop].ToString("x2"));

}

string hexDigest = sb.ToString();

string toDigest = "POST\n" + hexDigest + "\napplication/json\n" + dateValue + "\n/targets";

var hmacsha = new HMACSHA1(Encoding.ASCII.GetBytes(key));

byte[] bHash = hmacsha.ComputeHash(Encoding.ASCII.GetBytes(toDigest));

 

return Convert.ToBase64String(bHash);

}

 

Any suggestions? 

400 Bad Request

August 13, 2015 - 9:15am #9

Thanks. I had the same problem.

Had to typecast width to an integer for my case. Was a string and was getting the bad request error.

Beating my head wondering whats wrong.

400 Bad Request

September 2, 2014 - 12:28pm #8

I see my mistake now, the width was coming over as a string, I needed to remove the quotes from the JSON string I was creating.

 

Once I removed the quotes, the width is an appropriate float value and the AddTarget method works.

400 Bad Request

September 2, 2014 - 7:20am #7

Here is the JSON without the Authorization:

POST https://vws.vuforia.com/targets HTTP/1.1
Date: Tue, 02 Sep 2014 14:16:04 GMT
Content-Type: application/json
Host: vws.vuforia.com
Content-Length: 13430
Expect: 100-continue
Connection: Keep-Alive

{"name":"ffxtarget123","width":"320.0","image":"iVBORw0KGgoAAAANSUhEUgAAAOMAAABNCAIAAA......"}

400 Bad Request

August 29, 2014 - 2:27pm #6

Could you please post an output of your JSON text body that is generated by your code? We might be able to take a look at that and see if there is anything in the final formatting that might be triggering this error for you. Please exclude the Authorization when you post.

An example might be something like:

 

POST /targets HTTP/1.1
Host: vws.vuforia.com
Date: Mon, 23 Apr 2012 12:45:19 GMT
***Please exclude this part: Authorization: VWS df8d23140eb443505c0661c5b58294ef472baf64:jHX6oLeqTXpynyqcvVC2MSHarhU

Content-Type: application/json
{
“name”:”tarmac”,
“width":32.0,
“image”:”0912ba39x….”,
“application_metadata”:“496fbb6532b3863460a984de1d980bed5ebcd507”
}

 

400 Bad Request

August 29, 2014 - 2:06pm #5

Still getting an error.  Could you give an example of the width value and name value formatting?  As far as I can tell, my width value is formatted correctly, 320.0, which is a float value, and my name value is formatted correctely as well, it's a string value as far as I can see.  This code was generated from the php sample code that's available for setting up the API, if there is a different example I can look at or a link that shows the strictness required that would be good.

400 Bad Request

August 29, 2014 - 1:25pm #4

Developers have reported experiencing issues using the VWS API to add or update Cloud targets.  Please ensure that the values in the API requests are formatted properly.  Notably, “name” should be formatted as a string value, and “width” should be formatted as a float value.

API format validations are now more strictly enforced to avoid some downstream issues.

https://developer.vuforia.com/resources/dev-guide/adding-target-cloud-database-api
Please verify your API value types and let us know if you experience any further issues.

400 Bad Request

August 28, 2014 - 7:25pm #3

hi, I have the same problem since yesterday

400 Bad Request

August 28, 2014 - 7:20pm #2

Thank you for reporting this. We are currently investigating this issue.

Log in or register to post comments