Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some problems when using go-ipp #40

Open
codehuaa opened this issue Jul 22, 2024 · 1 comment
Open

Some problems when using go-ipp #40

codehuaa opened this issue Jul 22, 2024 · 1 comment

Comments

@codehuaa
Copy link

I can't decode the ipp request when using the go-ipp based on the demo. I don't know whether there're some mistakes when i use go-ipp. And here is my code, could you help review it.

// http resolver
r.POST("/ipp", func(c *gin.Context) {
    req, err := ipp.NewRequestDecoder(c.Request.Body).Decode(nil)
    if err != nil {
	fmt.Println(err.Error())
    } else {
	fmt.Println(req)
    }
})
// ipp client
// define a ipp request
req := ipp.NewRequest(ipp.OperationGetJobs, 1)
req.OperationAttributes[ipp.AttributeWhichJobs] = "completed"
req.OperationAttributes[ipp.AttributeMyJobs] = "myJobs"
req.OperationAttributes[ipp.AttributeFirstJobID] = 42
req.OperationAttributes[ipp.AttributeRequestingUserName] = "fabian"

// encode request to bytes
payload, err := req.Encode()
if err != nil {
	panic(err)
}

// send ipp request to remote server via http
httpReq, err := http.NewRequest("POST", "http://127.0.0.1:8080/ipp", bytes.NewBuffer(payload))
if err != nil {
	panic(err)
}

// set ipp headers
httpReq.Header.Set("Content-Length", string(len(payload)))
httpReq.Header.Set("Content-Type", ipp.ContentTypeIPP)

httpClient := &http.Client{}
httpResp, err := httpClient.Do(httpReq)
if err != nil {
	panic(err)
}
defer httpResp.Body.Close()

After i run these code, i got "EOF":

image

@phin1x
Copy link
Owner

phin1x commented Sep 29, 2024

Hi, first read the http body into a bytes buffer and then decode the buffer. we had similar problems in the issue #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants