Copy link to clipboard
Copied
Hi,
Below is that code that am trying to run in Indesign script. The URL http://localhost:4502/content/geometrixx/en/company/news/articles.html directly works in a browser, it gives back the content. But when I try running the below in Indesign, it gives the following result. It does not really give the conent back.
Indesign script code:
reply = "";
conn = new Socket;
// access Adobe’s home page
if (conn.open ("localhost:4502")) {
var request = "GET /content/geometrixx/en/company/news/articles.html HTTP/1.0\n\n" +
"Authorization: Basic admin:admin\n";
conn.write (request); // and read the server’s reply
reply = conn.read(999999);
alert(reply);
conn.close();
}
Output in Indesign:
HTTP/1.1 404 Not Found
Connection: Close
Server: Day-Servlet-Engine/4.1.12
Content-Type: text/html;charset=UTF-8
Content-Length: 387
Date: Wed, 07 Dec 2011 03:05:26 GMT
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /content/geometrixx/en/company/news/articles.html was not found on this server.</p>
<hr>
<address>ApacheSling/2.2 (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29; Mac OS X 10.7.2 x86_64)</address>
</body></html>
Hi,
Your code has some problems.
1. HTTP Request closed 1st line. Server wait and get data while "\n\n" come.
2. Authorization user name and password string must be encode base64.
You can read as reference :
http://en.wikipedia.org/wiki/Basic_access_authentication
here is a sample request:
var request = "GET /autharea/index.html HTTP/1.1\n"
+ "Host: (serverName)\n"
+ "Content-Type: text/html; charset=UTF-8\n"
+ "Authorization: Basic "+ encodedData +"\n\n";
an
...Copy link to clipboard
Copied
Hi,
Your code has some problems.
1. HTTP Request closed 1st line. Server wait and get data while "\n\n" come.
2. Authorization user name and password string must be encode base64.
You can read as reference :
http://en.wikipedia.org/wiki/Basic_access_authentication
here is a sample request:
var request = "GET /autharea/index.html HTTP/1.1\n"
+ "Host: (serverName)\n"
+ "Content-Type: text/html; charset=UTF-8\n"
+ "Authorization: Basic "+ encodedData +"\n\n";
and working code with base64 function
var authStr = "username:password";
var encodedData = base64(authStr );
var reply = "";
var conn = new Socket;
var request = "GET /autharea/index.html HTTP/1.1\n"
+ "Host: (serverName)\n"
+ "Content-Type: text/html; charset=UTF-8\n"
+ "Authorization: Basic "+ encodedData +"\n\n";
if (conn.open ("130.1.6.46:80","UTF-8")) {
conn.write (request);
reply = conn.read(999999);
conn.close();
alert(reply);
}
function base64(binaryString) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var encoded = "";
var c1, c2, c3;
var e1, e2, e3, e4;
var i = 0;
while(i < binaryString.length) {
c1 = binaryString.charCodeAt(i++);
c2 = binaryString.charCodeAt(i++);
c3 = binaryString.charCodeAt(i++);
e1 = c1 >> 2;
e2 = ((c1 & 3) << 4) | (c2 >> 4);
e3 = ((c2 & 15) << 2) | (c3 >> 6);
e4 = c3 & 63;
if (isNaN(c2)) {
e3 = e4 = 64;
} else if (isNaN(c3)) {
e4 = 64;
}
encoded = encoded + keyStr.charAt(e1) + keyStr.charAt(e2) +
keyStr.charAt(e3) + keyStr.charAt(e4);
}
return encoded;
}
Ten
Copy link to clipboard
Copied
yes, I have figured it out, thank you so much for the help.