1

我是网络服务器工作的新手。我正在尝试从 C# 客户端向我的 Java webservice 发出 webrequest POST。我相信 POST 已成功完成,但我不知道如何告诉服务器检索和使用 POST 数据。

这是我现在用 Java 编写的代码:

//import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.iharder.encoders.Base64;
import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

@Service("FCBarcodeRecognitionService")
public class DecodeBarcodeFromImageActivity extends Activity {

  private static final Log LOG = LogFactory
              .getLog(DecodeBarcodeFromImageActivity.class);

  @Operation("DecodeBarcodeFromImage")
  @Documentation("Attempt to decode a barcode from POST image data.\n  Returns a String of the decoded barcode and the type\n  of barcode detected if successful.")
  public DecodeFromImageOutput enact(DecodeFromImageInput input)
    throws DependencyException {

       DecodeFromImageOutput output = new DecodeFromImageOutput();
       LOG.debug("Received DecodeFromBarcodeImage request..."); 
       // Decode the images from the String arguments. They could
       // potentially be in any encoding format. (e.g. Base64)
       //How do I retrieve the POST data to use inside this operation??

       //I have something like this now
       ImageEncoder imageEncoder = new ImageEncoder();
       //the current input is just something I'm manually giving it. I want it to be the encoded image from the POST data
       List<BufferedImage> bufferedImgs = imageEncoder.decodeImageData(input);
       LOG.debug("Received " + bufferedImgs.size() + " images from decoder.");

       // Attempt to read a barcode (this will just pass the POST data, once I get it to my decode method)
       try {
           DecodedBarcode barcode = recognizeBarcodeFromImages(input, bufferedImgs);
           output.setDecodedBarcode(barcode);

这是我现在在 C# 中的代码://我正在尝试发布一个编码的(base64)图像

WebRequest serverReq = WebRequest.Create("http://saxtonl.desktop.amazon.com:8000/explorer");
serverReq.Method = "POST";
serverReq.ContentType = "application/x-www-form-urlencoded";
serverReq.ContentLength = base64String.Length;
Stream dataStream = serverReq.GetRequestStream();
dataStream.Write(imageBytes, 0, imageBytes.Length);
dataStream.Close();
WebResponse serverRsp = serverReq.GetResponse();
Console.WriteLine(((HttpWebResponse)serverRsp).StatusDescription);
dataStream = serverRsp.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
serverRsp.Close();
4

0 回答 0