WebRequest Error 5039

 

Hey Guys,

I try to write my first EA with serverside communication. Ive wrote a simple java spring boot application with a rest controller working fine in testing with postman. If I try to send a POST with the WebRequest function I am facing an error.

input string url = "localhost:8080/postSignal";

int OnInit(){
   sendMessage();
   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){
}

void OnTick(){
}

void sendMessage() {
   ResetLastError();
   string json = "{\"signal\" : \"XAUUSD\",\"openPrice\": 2000,\"sl\": 1999,\"tp\": 2001,\"magiic\": 123}";
   char jsonData[], result[];
   StringToCharArray(json,jsonData, 0, StringLen(json));
   string resultHeaders;
   string requestHeaders= "Content-Type: application/json";
   int res = WebRequest("POST", url, requestHeaders, 5000, jsonData, result, resultHeaders);
  
   printf("Response Code: " + res);
   printf("LastError Code: " + GetLastError());
   string serverResultString = CharArrayToString(result);
   printf("Result String: " + serverResultString);
}

Response Code: 400

LastError Code: 5039

The code is documented as ERR_TOO_MANY_PARAMETERS. I dont get what I am doing wrong here.

 
Need Java Spring Boot controller code to better diagnose the problem.
 
marvinduchmann:
\"magiic\": 123}";

Just something worth mentioning you are using /ii/.

 
Yashar Seyyedin #:

Just something worth mentioning you are using /ii/.

Thanks! Found this one too.
 
Oleksandr Medviediev #:
Need Java Spring Boot controller code to better diagnose the problem.

Heres the controller and the object definition. As mentioned, it works fine with a test in postman.

@RestController
public class SignalController {

    @PostMapping(value = "/postSignal", consumes = "application/json")
    public ResponseEntity<String> createSignal(@RequestBody Position position) {
        System.out.println(position);
        return new ResponseEntity<String>("Signal recieved", HttpStatus.OK);
    }

}

public class Position {

    private String signal;
    private double openPrice;
    private double sl;
    private double tp;
    private int magic;

    public Position(String signal, double openPrice, double sl, double tp, int magic) {
        this.signal = signal;
        this.openPrice = openPrice;
        this.sl = sl;
        this.tp = tp;
        this.magic = magic;
    }

    public String getSignal() {
        return signal;
    }

    public void setSignal(String signal) {
        this.signal = signal;
    }

    public double getOpenPrice() {
        return openPrice;
    }

    public void setOpenPrice(double openPrice) {
        this.openPrice = openPrice;
    }

    public double getSl() {
        return sl;
    }

    public void setSl(double sl) {
        this.sl = sl;
    }

    public double getTp() {
        return tp;
    }

    public void setTp(double tp) {
        this.tp = tp;
    }

    public int getMagic() {
        return magic;
    }

    public void setMagic(int magic) {
        this.magic = magic;
    }

    @Override
    public String toString() {
        return "Position{" +
                "signal='" + signal + '\'' +
                ", openPrice=" + openPrice +
                ", sl=" + sl +
                ", tp=" + tp +
                ", magic=" + magic +
                '}';
    }
}
 
Controller code looks correct. Got to be something else.
 

The error 5039 occurs because you are calling printf in a wrong way - you're adding integers to strings (you should pass each value as parameter instead, separating the string to be formatted and each value by commas) and are not passing any format specifier so the function can actually convert the passed parameters to the specified format. It has nothing to do with an request error.

Use Print instead of printf for convenience and separate each value by commas in the function call. Then we can see which error the WebRequest function is actually returning.

 
Emanuel Cavalcante Amorim Filho #:

The error 5039 occurs because you are calling printf in a wrong way - you're adding integers to strings (you should pass each value as parameter instead, separating the string to be formatted and each value by commas) and are not passing any format specifier so the function can actually convert the passed parameters to the specified format. It has nothing to do with an request error.

Use Print instead of printf for convenience and separate each value by commas in the function call. Then we can see which error the WebRequest function is actually returning.

Wow never thought about an error at the print function...... The error code is gone now, meaning its 0. But that does not give me any hint whats wrong:

Here is the full Print result:

2024.05.03 17:47:33.459    SignalSender (EURCAD,M1)    Response Code: 400
2024.05.03 17:47:33.459    SignalSender (EURCAD,M1)    LastError Code: 0
2024.05.03 17:47:33.459    SignalSender (EURCAD,M1)    Result String: <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>

 
Marvin Duchmann:

Hey Guys,

I try to write my first EA with serverside communication. Ive wrote a simple java spring boot application with a rest controller working fine in testing with postman. If I try to send a POST with the WebRequest function I am facing an error.

input string url = "localhost:8080/postSignal";
WebRequest is now allowing to use a non-standard port ?