I have a problem, I have a server that logs into another server and gets some data. The login works in NodeJS like this:
var data = {
login_act: "username",
login_pwd: "password"
};
request.post({url: 'https://example.com', form: data}, callback())`
and in Java like this:
try {
URL mUrl = new URL("https://example.com");
HttpURLConnection connection = (HttpURLConnection) mUrl.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
String urlParameters = "login_act=" + username + "&login_pwd=" + password;
byte[] postData = urlParameters.getBytes("UTF-8");
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
try( DataOutputStream wr = new DataOutputStream( connection.getOutputStream())) {
wr.write( postData );
}
}
I also made a C++ implementation of the same situation:
QNetworkAccessManager *vManager = new QNetworkAccessManager;
QNetworkRequest req;
req.setUrl(QUrl("https://example.com"));
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
QByteArray postData;
postData.append("login_act=" + username + "&");
postData.append("login_pwd=" + password + "");
connect(vManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(authFinished(QNetworkReply*)));
QNetworkReply *reply = vManager->post(req, postData);
reply->ignoreSslErrors();
But when I try to do the same in Go it refuses to log in:
resp, error := http.PostForm("https://example.com", url.Values{"login_act": {"username"}, "login_pwd": {"password"}})
The site is build in such a way that, when login fails it just returns the standard site with the login form and if login suceeds it returns a 302 statuscode. Maybe someone can help me I'm new to the go programming language and maybe I just miss something important. Thanks in advance.