Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

add custom header before submitting form

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

is it possible to add custom headers before submitting a form?

[problem]
I have to implement automatic login to a site which uses Basic Authentication. I need somehow to add the following header:
Authorization Basic base64enc(user : pass)
before submiting to the protected site.

Thanks in advance,
Deyan
[ May 09, 2005: Message edited by: Deyan Sultov ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't this the same question as:
https://coderanch.com/t/360419/Servlets/java/Automatic-Basic-Authentication
?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Submitting a form from where? What client?
If you are (for example) creating request from a Java client, you can set request properties with the method in URLConnection.
Bill
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, here is some my code, I can send a complete though:
boolean checkCredentials() {
String credentials = req.getHeader(AUTHORIZATION);
if (credentials!=null) {
int p = credentials.indexOf(' ');
if (p > 0 && credentials.substring(0, p).equalsIgnoreCase("Basic")) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new sun.misc.BASE64Decoder().decodeBuffer(new StringBufferInputStream(credentials.substring(p+1)), baos);
credentials = baos.toString();
p = credentials.indexOf(':');
if (p > 0) {
String password = credentials.substring(p+1);
String user = credentials.substring(0, p);
if ("Administrator".equals(user) &&
dispatcher.getProperty(PROP_PASSWORD, "")
.equals(Crypt.crypt("", password)))
return true;
}
} catch(IOException e) {
dispatcher.log(e.getMessage());
}
} else {
try {
resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED , "Not supported authorization type.");
} catch(IOException e) {
dispatcher.log(e.getMessage());
}
return false;
}
}
resp.setHeader(WWW_AUTHENTICATE, "Basic realm=\"Payment Administrator\"");
try {
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Provide your credentials for the authorization.");
resp.flushBuffer();
} catch(IOException e) {
dispatcher.log(e.getMessage());
}
return false;
}
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i never used this sort of authentification, so my answer might slightly miss the point.

But if you send your form from a webbrowser...

You can add key value pairs to the http header with a HTML Meta



J.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yes, here is some my code, I can send a complete though:


That appears to be server side code - but your question was about adding custom headers to a request on the client side.
 
D Rog
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, you are right.
 
Look ma! I'm selling my stuff!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic