我是java新手,最近几天一直在这个问题上纠结。我正在从java客户机向python服务器发送图像。我收到一个200的请求,意味着连接正在进行中。但是在服务器端无法读取图像。我已经包括了代码-任何帮助都会很好。在
服务器代码def index(request):
data = {"POST REQUEST, INSIDE INDEX, NO URL OR IMAGE SENT": False}
if request.method == "GET":
return HttpResponse("GET REQUEST WORKS. RR.")
if request.method == "POST":
# check to see if an image was uploaded
if request.FILES.get("image", None) is not None:
# grab the uploaded image
image = request.FILES["image"]
# otherwise, assume that a URL was passed in
else:
# grab the URL from the request
url = request.POST.get("url", None)
# if the URL is None, then return an error
if url is None:
return HttpResponse("no URL is specified")
# load the image and convert
image = _grab_image(url=url)
req = image
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
img = cv2.imdecode(arr,-1) # 'load it as it is'
Server = True
Student_Answers = []
image = doc_Scan(img)
if (image == "ERROR"):
return HttpResponse("TAKE ANOTHER PICTURE")
else:
images = crop_answer2(image)
for i in range(0,8):
ans = images[i]
Answer = Input_Image(ans,Server)
print ('Final Answer = ', Answer)
Student_Answers.append(Answer)
Results, score = mark_paper(Server,Student_Answers)
Worded_Respose = "The Student got ", score, " correct"
return HttpResponse(Results, content_type="application/json")
else:
return HttpResponse("NO POST REQUEST")
客户代码
^{pr2}$