x
all questions login
General DNS & Domains Dyn Email Update Clients Dyn Developer

Hello!

I am writing a small Program which shall be able to update my host-ip on dyndns. Due to the Java ME restrictions, I can´t use the direct url-command like:

http://user:psswdcptcomic@members.dyndns.org/nic/update?hostname=name.dyndns.info&myip=122.111.111.11"

So I have to perform a http GET, but when I try this:

HttpConnection conn =  (HttpConnection) Connector.open("http://members.dyndns.org");
DataOutputStream outs = conn.openDataOutputStream();
outs.writeChars("GET /nic/update?hostname=name&myip=123.123.122.3&wildcard=NOCHG&mx=NOCHG&backmx=
      NOCHG HTTP/1.0\n");
outs.writeChars("Host:members.dyndns.org\n");
outs.writeChars("Authorization: Basic "+BasicAuth.encode(username, password)+"\n");
outs.writeChars("User-Agent:FH KL Beta 1\n");
outs.flush();

I always get a 404 Error, just what happens if you enter http://members.dyndns.org in your adress-bar.

Can somebody please tell me what I am doing wrong? Thank you!!!

more ▼

asked Jan 26 at 09:54 PM

Sebastian\'s gravatar image

Sebastian
11 1 1 2

10|600 characters needed characters left

2 answers:

First of all, the HttpConnection class is made specifically to handle HTTP connections, and it does so with its built-in managed features. When using a managed object such as an HttpConnection object, you're not directly controlling the low-level aspects of the connection in a traditional sense, but you can manipulate it indirectly. Just keep in mind that you are not opening a generic TCP/IP connection, but an HTTP connection :-)

When you send chars to the DataOutputStream, you are actually sending a request body (not headers). At that time, the HttpConnection Class has already initiated the connection, sent the initial "GET" command and any default headers.

As you can see in this line, you have already specified the URI (for the GET command) to be "http://members.dyndns.org":

HttpConnection conn = (HttpConnection) Connector.open("http://members.dyndns.org");

To explicitly set an HTTP header, use the setRequestProperty method.

I'll thow you an example:

// Declarations
string sHostname = "myhost.dyndns.org";
string sIP = "1.2.3.4";
string sUsername = "myusername";
string sPassword = "mypassword";
int iResponseCode;

// Defining the URL
string sURL = "http://members.dyndns.org/nic/update?hostname=" + sHostname + "&myip=" + sIP;

// Creating the HTTP request
conn =  (HttpConnection) Connector.open(sURL);
conn.setRequestProperty("Authorization", "Basic " + BasicAuth.encode(sUsername, sPassword);
conn.setRequestProperty("User-Agent", "My insanely cool mobile DDNS updater");

// Making it happen, by calling the getResponseCode() method
iResponseCode = conn.getResponseCode();

Hope this helps.

EDIT: By the way, you should make sure you read the InputStream as well, to read the actual response string from the update API.

more ▼

answered Jan 27 at 07:05 PM

VikingTiger\'s gravatar image

VikingTiger ♦
11.6k 2 10 124

10|600 characters needed characters left

It would help if you could provide the full 404 error returned.

more ▼

answered Jan 26 at 10:39 PM

Cry Havok\'s gravatar image

Cry Havok ♦
52.2k 13 26 222

10|600 characters needed characters left
Your answer
osqa.question.ask.tags.preview.show

© 1998-2012  Dynamic Network Services Inc.  -  Legal Notices  -  Privacy Policy  -  Contacts     

Powered by AnswerHub - Enterprise Social Q&A