Jersey: http error 400 - post

I need to write a Jersey Client in Spring.
Using CURL, this works:
curl --header "Authorization: Basic aaaaaaabbbbb" --header "Content-Type: application/json" --request POST "http://163.162.8.112:9000/path" --data #TestWrapperJob.json
--> return a STRING
-- TestWrapper.json
{ "name": "job2aad",
"description": "Descrizione test job1",
"tests": [ {
"TestPath": "EsempiRiccardo\\TestWrapper",
"TestDuration": "2"
} ],
"topology": null
}
Now I'm trying to translate in JAVA, but i get HTTP ERROR 400
Client client = Client.create();
String temp = "{ \"name\": \"job2aad\", "
+ " \"description\": \"Descrizione test job1\", "
+ " \"tests\": [ { "
+ " \"TestPath\": \"EsempiRiccardo\\TestWrapper\", "
+ " \"TestDuration\": \"2\" "
+ " } ], "
+ " \"topology\": null "
+ "}";
WebResource webResource = client.resource("http://163.162.8.112:9000/path");
ClientResponse response = webResource.header("Authorization", "Basic aaaaaaabbbbb")
.type("application/json")
.post(ClientResponse.class, temp);
What's wrong?
Riccardo

Ok, sorry to all...
I found the answer
+ " \"TestPath\": \"EsempiRiccardo\\TestWrapper\", "
should be
+ " \"TestPath\": \"EsempiRiccardo\\\\TestWrapper\", "

Related

appium-java Unknown HttpClient factory apache when initializing driver

I'm trying to migrate from appium-java client 7.0 to 8.3 - After updating to 8.3 version I get an error when initializing appium driver (for iOS)
java.lang.IllegalArgumentException: Unknown HttpClient factory apache
at org.openqa.selenium.remote.http.HttpClient$Factory.create(HttpClient.java:57)
at org.openqa.selenium.remote.http.HttpClient$Factory.createDefault(HttpClient.java:73)
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:108)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:106)
Command to start appium server is build smth like this
command = nodePath + " " + appiumMainJS + " ";
command = command + " -a " + hostName + " -p " + availablePort + " ";
command = command + " -cp " + (availablePort + 1000) + " -bp " + (availablePort + 2000);
command = command + " --chromedriver-port " + (availablePort + 3000);
command = command + " " + appiumArgs;
Capabilities
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, OS_VERIOSN);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
capabilities.setCapability("appium:keychainPath", KEYCHAIN_PATH);
capabilities.setCapability("appium:keychainPassword", KEYCHAIN_PASSWORD);
capabilities.setCapability("appium:xcodeOrgId", XCODE_ORG_ID);
capabilities.setCapability("appium:xcodeSigningId", XCODE_SIGNING_ID);
capabilities.setCapability("appium:deviceName", DEVICE_NAME);
capabilities.setCapability("appium:showXcodeLog", true);
capabilities.setCapability("appium:noReset", false);
capabilities.setCapability("appium:simpleIsVisibleCheck", false);
capabilities.setCapability(MobileCapabilityType.UDID, DEVICE_ID);
capabilities.setCapability("appium:newCommandTimeout", "2000000");
capabilities.setCapability("appium:launchTimeout", "120000");
capabilities.setCapability("appium:shouldUseSingletonTestManager", false);
capabilities.setCapability("appium:wdaConnectionTimeout", 15*60*1000);
capabilities.setCapability("appium:sendKeyStrategy", "setValue");
capabilities.setCapability("appium:session-override", true);
capabilities.setCapability("appium:webkitResponseTimeout", 20000);
capabilities.setCapability("appium:useJSONSource", true);
capabilities.setCapability("appium:sendKeyStrategy", "grouped");
capabilities.setCapability("appium:commandTimeouts", "1000000");
capabilities.setCapability("appium:webDriverAgentUrl", customWdaUrl);
capabilities.setCapability("appium:webDriverAgentUrl", WDA_SERVER_URL);
capabilities.setCapability(IOSMobileCapabilityType.WDA_LOCAL_PORT, wdaPort);
Driver is initialized like this
IOSDriver iosDriver = new IOSDriver(url, capabilities);
What could be the issue here?

Stop running the program because WebView

My program runs successfully and the simulator runs, but all at once end.
An error occurs on this:
mWebView.LoadDataWithBaseURL("", str1, "text/html", "utf-8", null);
WebView mWebView = FindViewById<WebView>(Resource.Id.webView1);
String str1 =
"<html>" +
"<head>" +
"<style type='text/css'>" +
"#font-face {font-family:SFont; src:url('file:///android_asset/fonts/MyFont.TTF');}" +
"#font-face {font-family:TFont; src:url('file:///android_asset/fonts/times.ttf');}" +
"Ptext {" +
"font-family: SFont;" +
"font-size: 19px;" +
"text-align: justify;" +
"}" +
"Etext {" +
"font-family: TFont;" +
"font-size: 13px;" +
"text-align: justify;" +
"}" +
"body {" +
"text-align: justify;" +
"}" +
"</style>" +
"</head>" +
"<body dir = rtl>" +
"<font style='opacity:0.79'>" +
"<font color='white'>" +
"<Ptext>" + "Hello Hello" + " " + "</Ptext>" +
"<Etext>" + "Hello Hello" + "</Ptext>" +
"</font>" +
"</body>" +
"</html>";
mWebView.SetBackgroundColor(Color.ParseColor("#00000000"));
mWebView.LoadDataWithBaseURL("", str1, "text/html", "utf-8", null);
ERRORS:
[ERROR:gl_surface_egl.cc(327)] No suitab EGL configs found.
[ERROR:gl_surface_egl_android.cc(23)] GLSurfaceEGL::InitializeOneOff faild.
[Error:browser_main_lppo.cc(698)]GLSurdace::InitializeOneOff faild
[FATAL:gl_Surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation()(0 vs. 0)

HTTPS Post Request with ESP8266

I'm trying to send an HTTPS POST request with a ESP8266. I can make the request just fine with python and cURL just when I try it with the ESP it doesn't work. A segment of my code is below
const char *host = "api.pushbullet.com";
const int httpsPort = 443;
const char fingerprint[] PROGMEM = "4C 70 C5 AE F3 30 E8 29 D1 9C 18 C6 2F 08 D0 6A A9 AA 19 0F";
Link = "/post";
httpsClient.print(String("POST ") + Link + " HTTP/1.1\r\n" +
"Host: " + host + "/v2/pushes" + "\r\n" +
"Access-Token: *************"+ "\r\n" +
"Content-Type: application/json"+ "\r\n" +
"Content-Length: 20"+ "\r\n" +
"body: Hello World" + "\r\n\r\n");
Serial.println("request sent");
The request I'm trying to make is below. This works just fine in python
import requests
headers = {
'Access-Token': '***********',
'Content-Type': 'application/json',
}
data = '{"body":"Hello World","title":"Hi","type":"note"}'
response = requests.post('https://api.pushbullet.com/v2/pushes', headers=headers, data=data)
And in cURL:
curl --header 'Access-Token: **********' --header 'Content-Type: application/json' --data-binary '{"body":"Hello World","title":"Hi","type":"note"}' --request POST https://api.pushbullet.com/v2/pushes
When I make the request with the Arduino code it returns "Error 411 (Length Required)!!".
This is probably due to some stupid mistake I've made but if anyone could help me fix my Arduino code I'd be very grateful. Thanks
There are a few mistakes in your code.
your http POST format are incorrect in a)host name, b)uri, and c)header/body separation;
your http body is not a valid json object.
Here is an example on sending the http (without using String):
const char *host = "api.pushbullet.com";
const char *uri = "/post/v2/pushes/";
const char *body ="{\"body\": \"Hello World\"}"; // a valid jsonObject
char postStr[40];
sprintf(postStr, "POST %s HTTP/1.1", uri); // put together the string for HTTP POST
httpsClient.println(postStr);
httpsClient.print("Host: "); httpsClient.println(host);
httpsClient.println("Access-Token: *************");
httpsClient.println("Content-Type: application/json");
httpsClient.print("Content-Length: "); httpsClient.println(strlen(body));
httpsClient.println(); // extra `\r\n` to separate the http header and http body
httpsClient.println(body);
General advice: when you use cURL always use --verbose to see the full HTTP exchange.
In your case it should be
httpsClient.print(String("POST ") + "/v2/pushes" + Link + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Access-Token: *************"+ "\r\n" +
"Content-Type: application/json"+ "\r\n" +
"Content-Length: 20"+ "\r\n" +
"body: Hello World" + "\r\n\r\n");
Note how
the path is "/v2/pushes/" plus identifier ("Link" in your case?)
Host is just "api.pushbullet.com"
Side notes:
make sure you send correct values for Content-Length
consider using HTTPClient if you are not confident with low-level HTTP programming

Trying to connect to host

I'm trying to connect to Google Firebase Firestore using an esp8266 device. I want to do a post request but can't get a connection to the host:
const char *host = "firestore.googleapis.com";
int r=0; //retry counter
while((!httpsClient.connect(host, httpsPort)) && (r < 30)){
delay(50);
Serial.print(".");
r++;
}
httpsClient.print(String("POST ") + "/v1beta1/projects/myproject/databases/(default)/documents/loggings" + " HTTP/1.1\r\n" +
"Host: " + "firestore.googleapis.com" + "\r\n" +
"Content-Type: application/json"+ "\r\n" +
"Content-Length: 240" + "\r\n\r\n" +
postData+ "\r\n" +
"Connection: close\r\n\r\n");
The connect() function doesn't work because the host can't be found (404). How do I need to use the connect function to get a proper connection to the firestore host?
Call httpsClient.setInsecure() before connect(). Key validation is then skipped. It's not secure but maybe that's ok for your use case. httpsPort should be 443. For me connecting to fcm.googleapis.com works if done like this:
WiFiClientSecure client;
client.setInsecure(); // INSECURE!
client.connect("fcm.googleapis.com", 443);

Google Analytics & Blackberry UserAgent

I'm using this code to get the blackberry info on google analytics
private static String getUserAgent()
{
String userAgent = "Blackberry" + DeviceInfo.getDeviceName() + "/" +
getOsVersion() + " Profile/" + System.getProperty(
"microedition.profiles" ) + " Configuration/" + System.getProperty(
"microedition.configuration" ) + " VendorID/" +
Branding.getVendorId();
return userAgent;
}
And then using it here :
conn.setRequestProperty("User-Agent", userAgent);
The problem is that it doesn't recognize the terminal like a mobile phone , but it takes difference in browser .
Browser:
Navegador Visitas % Visitas
1. Blackberry8900 36 100,00%
Any idea if google analytics have some params to know that is a mobile phone ? or if i'm using a badformated useraggent.
Thanks for your answers.

Resources