Essentially I’m trying to put a variable (preview3DID) into the data parameter of the post method and it’s not working. When I manually put in the ID it works fine but when I try to add the ID with concatenation it doesn’t work. Is there another method of concatenation that I should be using or does this just not work entirely. Code is below.
Send the same request to https://httpbin.org/post and print out the output. It sends back json containing the stuff it itself received from you. Most likely there is something weird, such as some non-printable characters involved.
Uhm, the snippet you posted doesn’t really have the string in quotation marks. So where / when is that string variable actually filled? The snippet you posted would not work
What output do you actually get from the first API? I would assume that you get json back, right? So you should properly parse the json.
I actually wrote my SimpleJSON specifically for requesting webservices. With it you could simply do
var data = JSON.Parse(previewRequest.downloadHandler.text);
preview3DID = data["result"].Value;
You can also use it to create your request json
JSONNode data = new JSONObject();
data["mode"] = "preview";
data["prompt"] = "a monster mask";
data["art_style"] ="realistic";
data["should_remesh"] = true;
string json = data.ToString();
And for your other request:
JSONNode data = new JSONObject();
data["mode"] = "refine";
data["preview_task_id"] = preview3DID;
data["enable_pbr"] = true;
string json = data.ToString();
You can use any json library, but most require to either create a class for each request / response or are quite large. Mine is a single script file and the aim was ease of use
I believe this is the problem. Here you have a conversion to UTF-8 string and that string includes Unicode BOM. When output it to console, you don’t see it, as it’s non-printable.
This may help:
Or if the token is guaranteed to be like that, convert bytes to string using ASCII encoding.
So I did what you said and the json worked for the first request but for the second it’s still saying that the preview task isn’t there. Here’s the code: