Why is the CURL command throwing following error when I look to transfer the jar file from my server to nexus repository
curl -v -F r=1 -F hasPom=false -F e=jar -F g=org.sonatype.plugins -F a=nexus-staging-maven-plugin -F v=1.0 -F p=jar -F file=mozaic-1.0-SNAPSHOT.jar -u admin:Easy123 http://192.168.12.176:8081/repository/maven-snapshots/
* TCP_NODELAY set
* Connected to 192.168.12.176 (192.168.12.176) port 8081 (#0)
* Server auth using Basic with user 'admin'
> POST /repository/maven-snapshots/ HTTP/1.1
> Host: 192.168.12.176:8081
> Authorization: Basic YWRtaW46RWFzeTEyMw==
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Length: 860
> Content-Type: multipart/form-data; boundary=------------------------d5e1136698e938a7
>
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 405 POST
< Server: Nexus/3.41.0-01 (OSS)
< X-Content-Type-Options: nosniff
< Content-Security-Policy: sandbox allow-forms allow-modals allow-popups allow-presentation allow-scripts allow-top-navigation
< X-XSS-Protection: 1; mode=block
< Allow: GET,HEAD,PUT,DELETE
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: text/html
< Content-Length: 1738
<
<!DOCTYPE html>
<html lang="en">
<head>
<title>405 - Nexus Repository Manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--[if lt IE 9]>
<script>(new Image).src="../../favicon.ico?3.41.0-01"</script>
<![endif]-->
<link rel="icon" type="image/png" href="../../favicon-32x32.png?3.41.0-01" sizes="32x32">
<link rel="mask-icon" href="../../safari-pinned-tab.svg?3.41.0-01" color="#5bbad5">
<link rel="icon" type="image/png" href="../../favicon-16x16.png?3.41.0-01" sizes="16x16">
<link rel="shortcut icon" href="../../favicon.ico?3.41.0-01">
<meta name="msapplication-TileImage" content="../../mstile-144x144.png?3.41.0-01">
<meta name="msapplication-TileColor" content="#00a300">
<link rel="stylesheet" type="text/css" href="../../static/css/nexus-content.css?3.41.0-01"/>
</head>
<body>
<div class="nexus-header">
<a href="../..">
<div class="product-logo">
<img src="../../static/rapture/resources/icons/x32/nexus-white.png?3.41.0-01" alt="Product logo"/>
</div>
<div class="product-id">
<div class="product-id__line-1">
<span class="product-name">Nexus Repository Manager</span>
</div>
<div class="product-id__line-2">
<span class="product-spec">OSS 3.41.0-01</span>
</div>
</div>
</a>
</div>
<div class="nexus-body">
<div class="content-header">
<img src="../../static/rapture/resources/icons/x32/exclamation.png?3.41.0-01" alt="Exclamation point" aria-role="presentation"/>
<span class="title">Error 405</span>
<span class="description">Method Not Allowed</span>
</div>
<div class="content-body">
<div class="content-section">
POST
</div>
</div>
</div>
</body>
</html>
* Connection #0 to host 192.168.12.176 left intact
You're getting the following response from the Nexus server: < HTTP/1.1 405 POST
.
And in the HTML response body we can (also) see what HTTP 405 POST means:
Error 405 Method Not Allowed
So the POST
method is not allowed on this URL. That is the result of trying to do a form
upload via curl, which is not supported. The Nexus server also kindly responds with the methods it does allow: < Allow: GET,HEAD,PUT,DELETE
If you want to upload a file into a repository, you are supposed to use a HTTP PUT
command. You can find the documentation for how this is executed online:
For example a direct deploy with curl
for nexus 2 (and also 3, the command is the same besides the specific /repositories
path):
You can do an HTTP PUT of a file into /content/repositories/<repo-id>/<path-of-file>. Using curl you can do this with:
curl -v -u admin:admin123 --upload-file pom.xml http://localhost:8081/nexus/content/repositories/releases/org/foo/1.0/foo-1.0.pom
Watch out; you're supposed to manually put the correct groupid
, artifactid
, version
and desired filename
into this URL, otherwise you'll upload the file in the root of the repository! In this example that would be the last part of the URL: org/foo/1.0/foo-1.0.pom
An example of executing this on a Nexus server i have access to:
curl -v -u user:pass --upload-file some.jar http://host/nexus/content/repositories/repo/group/artifact/version/some.jar
With curl
command logging (minus REDACTED private information):
* Trying host...
* Connected to host (ip) port PORT (#0)
* Server auth using Basic with user 'user'
> PUT /nexus/content/repositories/REDACTED HTTP/1.1
> Host: REDACTED
> Authorization: Basic REDACTED
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Length: 18783
> Expect: 100-continue
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Date: Wed, 31 Aug 2022 15:01:50 GMT
< Server: Nexus/2.10.0-02
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Tue, 30-Aug-2022 15:01:50 GMT
< Accept-Ranges: bytes
< Content-Length: 0
<
* Connection #0 to host REDACTED left intact
And as we can see this uploaded the artifact: * We are completely uploaded and fine
with result < HTTP/1.1 201 Created