Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

java - How to add array to okhttp body (POST)

Now i`m adding array as string to body:

RequestBody body = new FormEncodingBuilder()
    .add("profiles", "[122, 125, 336]")
    .build();

But the server need array on post parameter. How can i add array instead of string? Is it posible with okhttp?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are currently posting profiles as a string. You will want to mimic a POST for a checkbox form field for profiles

RequestBody body = new FormEncodingBuilder()
    .add("profiles[0]", "122")
    .add("profiles[1]", "125")
    .add("profiles[2]", "336")
    .build();

more info and good reading,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...