Request response 401

I receive a response 401 when trying to upload a file from my local machine in one of my requests. I have ran the script in DEBUG mode and receive this:

13:06:06.940 [DEBUG] i.g.h.e.r.DefaultStatsProcessor - Request 'UPLOAD' failed for user 1: status.find.in([200, 209], 304), found 401
13:06:06.958 [DEBUG] i.g.h.e.r.DefaultStatsProcessor - 
>>>>>>>>>>>>>>>>>>>>>>>>>>
Request:
UPLOAD: KO status.find.in([200, 209], 304), found 401
=========================
Session:
Session(V7UploadPNG,1,HashMap(gatling.http.cache.baseUrl -> https://mht03ccweb01:8081, gatling.http.ssl.sslContexts -> io.gatling.http.util.SslContexts@2d11acd2, gatling.http.referer -> https://mht03ccweb01:8081/cc/FileUpload.do, gatling.http.cookies -> CookieJar(Map(CookieKey(jsessionid,mht03ccweb01,/cc) -> StoredCookie(JSESSIONID=1F8D83CC59679E15BC3EBA8422661D79, path=/cc, secure, HTTPOnly,true,false,1714392338598), CookieKey(rcounter,mht03ccweb01,/cc) -> StoredCookie(rcounter=5,true,false,1714392354886))), gatling.http.cache.dns -> io.gatling.http.resolver.ShufflingNameResolver@33cd6290, gatling.http.cache.contentCache -> io.gatling.core.util.cache.Cache@7ca4c165),KO,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda/0x00000216d54f2968@519c2190,io.netty.channel.nio.NioEventLoop@2fe88a09)
=========================
HTTP request:
POST https://mht03ccweb01:8081/cc/FileUpload.do
headers:
	authorization: Basic a21jYnI=:Z3c5OQ==
	dnt: 1
	Cache-Control: no-cache
	accept-language: en-US, en-GB; q=0.7, en; q=0.3
	accept: image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*
	user-agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729)
	Content-Type: multipart/form-data; boundary=---------------------------7e8803768040e
	accept-encoding: gzip, deflate
	referer: https://mht03ccweb01:8081/cc/ClaimCenter.do?ts=43304164
	cookie: JSESSIONID=1F8D83CC59679E15BC3EBA8422661D79; rcounter=5
	origin: https://mht03ccweb01:8081
	host: mht03ccweb01:8081
	content-length: 572
cookies:
	JSESSIONID=1F8D83CC59679E15BC3EBA8422661D79, path=/cc, secure, HTTPOnly
	rcounter=5
body:ByteArrayRequestBody{content (Base64)=LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS03ZTg4MDM3NjgwNDBlDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7IG5hbWU9IndpZGdldFJlbmRlcklkIg0KDQpDbGFpbU5ld0RvY3VtZW50TGlua2VkV29ya3NoZWV0Ok5ld0RvY3VtZW50TGlua2VkU2NyZWVuOkRvY3VtZW50QXR0YWNobWVudERWOkF0dGFjaG1lbnQNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2U4ODAzNzY4MDQwZQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmaWxlUGF0aCINCg0KDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTdlODgwMzc2ODA0MGUNCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0iY29tbWl0Q3VycmVudExvY2F0aW9uIg0KDQoNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tN2U4ODAzNzY4MDQwZQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmaWxlQ29udGVudCI7IGZpbGVuYW1lPSJjbGFpbWNlbnRlcnY3XFRlc3REdXJhdGlvbl8yLnBuZyINCkNvbnRlbnQtVHlwZTogaW1hZ2UveC1wbmcNCg0KwolQTkc=}
=========================
HTTP response:
version:
	HTTP/1.1
status:
	401 Unauthorized
headers:
	Server: Apache-Coyote/1.1
	Content-Type: text/html;charset=utf-8
	Content-Language: en
	Content-Length: 951
	Date: Mon, 29 Apr 2024 12:06:07 GMT

body:
<html><head><title>Apache Tomcat/7.0.82 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.82</h3></body></html>
<<<<<<<<<<<<<<<<<<<<<<<<<

Is there anything that I am missing?

Hi @Keith,

Can you provide the code of your Simulation?

But from what I can see:

401, google search for 401 http status => " The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the target resource ."

So, I guess the issue is about the authorization header.
I can see it provided, but the format feel weird.

What should be base64(username + ":" + password)
But here, it seems you did: base64(username) + ":" + base64(password)

Try to change that.

If you used http.basicAuth, please fill an issue.

Cheers!

Thanks for the quick reply I think I’ve tried every variation I can think off and still the same response

Did you try http.basicAuth?

Are you sure your server expect basic authentication?
I see that the current code you provide doesn’t prefix with the "basic " scheme (to differentiate from bearer, token, user and the like)

If you want to set it at protocol level, authorizationHeader might be useful, indeed.

  public static String base64Credentials = Base64.getEncode().encodeToString((USERNAME + ": " + PASSWORD).getBytes());

  private HttpProtocolBuilder httpProtocol = http
    .baseUrl("https://mht03ccweb01:8081")
    .authorizationHeader("basic " + base64Credentials)

Cheers!

yes I have tried http.basic as well
image

  1. Are you really sure that your API is secured with the Basic auth mechanism and not something else?
  2. Are you sure that your API properly handles HTTP header names in a case insensitive fashion as required by the HTTP specification?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.